Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LIUKRAST committed Sep 11, 2024
1 parent 974b8d5 commit 246b6ba
Show file tree
Hide file tree
Showing 33 changed files with 940 additions and 30 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ loader_version_range=[4,)
mod_id=frozenlib
mod_name=FrozenLib
mod_license=All Rights Reserved
mod_version=1.0.5
mod_version=1.2.0
mod_group_id=net.frozenblock.frozenlib
mod_authors=LiukRast, Lunade, Treetrain1
mod_description=NeoForge port of FrozenLib
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/frozenblock/lib/FrozenMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.frozenblock.lib.entrypoint.api.FrozenModInitializer;
import net.frozenblock.lib.gravity.api.GravityAPI;
import net.frozenblock.lib.ingamedevtools.RegisterInGameDevTools;
import net.frozenblock.lib.item.api.FrozenCreativeModeTabs;
import net.frozenblock.lib.networking.FrozenNetworking;
import net.frozenblock.lib.particle.api.FrozenParticleTypes;
import net.frozenblock.lib.registry.api.FrozenRegistry;
Expand All @@ -28,6 +29,7 @@
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
import net.neoforged.neoforge.registries.RegisterEvent;
import org.quiltmc.qsl.frozenblock.core.registry.api.sync.ModProtocol;
import org.quiltmc.qsl.frozenblock.core.registry.impl.sync.server.ServerRegistrySync;
Expand Down Expand Up @@ -89,4 +91,9 @@ public void registerEvent(RegisterEvent event) {
);
});
}

@SubscribeEvent
public void registerTabs(BuildCreativeModeTabContentsEvent event) {
FrozenCreativeModeTabs.build(event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.frozenblock.lib.block.api;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.properties.BlockSetType;
import net.minecraft.world.level.block.state.properties.WoodType;

public class FrozenTypeBuilders {

public static BlockSetType copyOf(BlockSetType original, ResourceLocation id) {
return new BlockSetType(
id.toString(),
original.canOpenByHand(),
original.canOpenByWindCharge(),
original.canButtonBeActivatedByArrows(),
original.pressurePlateSensitivity(),
original.soundType(),
original.doorClose(),
original.doorOpen(),
original.trapdoorClose(),
original.trapdoorOpen(),
original.pressurePlateClickOff(),
original.pressurePlateClickOn(),
original.buttonClickOff(),
original.buttonClickOn()
);
}

public static WoodType copyOf(WoodType original, BlockSetType setType, ResourceLocation id) {
return new WoodType(
id.toString(),
setType,
original.soundType(),
original.hangingSignSoundType(),
original.fenceGateClose(),
original.fenceGateOpen()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.frozenblock.lib.block.api.fire;

import net.minecraft.world.level.block.state.BlockState;

public interface FireBlockInfo {
int getSpreadChance(BlockState block);
int getBurnChance(BlockState block);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.frozenblock.lib.block.api.fire;

import lombok.Getter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;

import java.util.HashMap;
import java.util.Map;

public class FrozenFlammableBlockRegistry {


private static final Map<Block, FrozenFlammableBlock> map = new HashMap<>();

public static FrozenFlammableBlock get(Block block) {
if(!map.containsKey(block)) map.put(block, new FrozenFlammableBlock());
return map.get(block);
}

public static FrozenFlammableBlock get() {
return get(Blocks.FIRE);
}

public static class FrozenFlammableBlock {
private FrozenFlammableBlock() {}
private final HashMap<Block, Entry> map = new HashMap<>();
public void add(Block block, int spreadChance, int burnChance) {
this.map.put(block, new Entry(spreadChance, burnChance));
}

public Entry get(Block block) {
return map.get(block);
}

@Getter
public static class Entry {
private final int spreadChance,burnChance;
private Entry(int spreadChance, int burnChance) {
this.spreadChance = spreadChance;
this.burnChance = burnChance;
}

}
}
}
30 changes: 30 additions & 0 deletions src/main/java/net/frozenblock/lib/block/api/fuel/FuelEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.frozenblock.lib.block.api.fuel;

import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.ItemLike;
import net.neoforged.bus.api.Event;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;

public class FuelEvent extends Event {
private final Map<ItemLike, Integer> itemLike = new HashMap<>();
private final Map<TagKey<Item>, Integer> itemTag = new HashMap<>();
public void add(ItemLike item, int time) {
itemLike.put(item,time);
}

public void add(TagKey<Item> tag, int time) {
itemTag.put(tag, time);
}

public void forItemLike(BiConsumer<ItemLike, Integer> consumer) {
itemLike.forEach(consumer);
}

public void forItemtag(BiConsumer<TagKey<Item>, Integer> consumer) {
itemTag.forEach(consumer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package net.frozenblock.lib.block.mixin.fire;

import net.frozenblock.lib.block.api.fire.FireBlockInfo;
import net.frozenblock.lib.block.api.fire.FrozenFlammableBlockRegistry;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FireBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(FireBlock.class)
public abstract class FireBlockMixin implements FireBlockInfo {

@Shadow
public abstract int getBurnOdds(BlockState state);

@Shadow
public abstract int getIgniteOdds(BlockState state);

@Unique
private FrozenFlammableBlockRegistry.FrozenFlammableBlock frozenLibNeoForge$block;

@Inject(at = @At("RETURN"), method = "<init>")
private void init(BlockBehaviour.Properties properties, CallbackInfo ci) {
frozenLibNeoForge$block = FrozenFlammableBlockRegistry.get((Block)(Object)this);
}

@SuppressWarnings("all")
@Inject(at = @At("HEAD"), method = "getBurnOdds", cancellable = true)
private void addBurn(BlockState state, CallbackInfoReturnable cir) {
final Integer get = frozenLibNeoForge$get(state, true);
if(get != null)
cir.setReturnValue(get);
}

@SuppressWarnings("all")
@Inject(at = @At("HEAD"), method = "getIgniteOdds", cancellable = true)
private void addIgnite(BlockState state, CallbackInfoReturnable cir) {
final Integer get = frozenLibNeoForge$get(state, false);
if(get != null)
cir.setReturnValue(get);
}

@Unique
private Integer frozenLibNeoForge$get(BlockState state, boolean burn) {
final FrozenFlammableBlockRegistry.FrozenFlammableBlock.Entry i = frozenLibNeoForge$block.get(state.getBlock());
if(i != null) {
if(state.hasProperty(BlockStateProperties.WATERLOGGED) && state.hasProperty(BlockStateProperties.WATERLOGGED))
return 0;
else
return burn ? i.getBurnChance() : i.getSpreadChance();
}
return null;
}

@Override
public int getSpreadChance(BlockState block) {
return getIgniteOdds(block);
}

@Override
public int getBurnChance(BlockState block) {
return getBurnOdds(block);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.frozenblock.lib.block.mixin.fuel;

import com.mojang.datafixers.util.Either;
import net.frozenblock.lib.FrozenSharedConstants;
import net.frozenblock.lib.block.api.fuel.FuelEvent;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import net.neoforged.neoforge.common.NeoForge;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.function.ObjIntConsumer;

@Mixin(AbstractFurnaceBlockEntity.class)
public abstract class AbstractFurnaceBlockEntityMixin {

@Shadow
private static void add(ObjIntConsumer<Either<Item, TagKey<Item>>> consumer, ItemLike item, int time) {
FrozenSharedConstants.LOGGER.warn("Injection failed {}add({};{};{}I)V", AbstractFurnaceBlockEntityMixin.class, ObjIntConsumer.class, ItemLike.class, ItemLike.class);
}

@Shadow
private static void add(ObjIntConsumer<Either<Item, TagKey<Item>>> consumer, TagKey<Item> tag, int time) {
FrozenSharedConstants.LOGGER.warn("Injection failed {}add({};{};{}I)V", AbstractFurnaceBlockEntityMixin.class, ObjIntConsumer.class, TagKey.class, ItemLike.class);

}

@Inject(at = @At("HEAD"), method = "buildFuels")
private static void addCustom(ObjIntConsumer<Either<Item, TagKey<Item>>> map1, CallbackInfo ci) {
final FuelEvent event = new FuelEvent();
NeoForge.EVENT_BUS.post(event);
event.forItemLike((itemLike, i) -> add(map1, itemLike, i));
event.forItemtag((tag, i) -> add(map1, tag, i));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.frozenblock.lib.blockEntity.api;

import net.minecraft.world.level.block.Block;

public interface FrozenBlockEntityType {
/**
* Allows registration of valid blocks to an already existing block entity*/
void addValidBlocks(Block ... blocks);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.frozenblock.lib.blockEntity.mixin;

import net.frozenblock.lib.blockEntity.api.FrozenBlockEntityType;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.Arrays;
import java.util.Set;

@Mixin(BlockEntityType.class)
public class BlockEntityTypeMixin implements FrozenBlockEntityType {

@Shadow @Final private Set<Block> validBlocks;

@Override
public void addValidBlocks(Block... blocks) {
validBlocks.addAll(Arrays.asList(blocks));
}
}
Loading

0 comments on commit 246b6ba

Please sign in to comment.