generated from NeoForgeMDKs/MDK-1.21-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
940 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/net/frozenblock/lib/block/api/FrozenTypeBuilders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/net/frozenblock/lib/block/api/fire/FireBlockInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/net/frozenblock/lib/block/api/fire/FrozenFlammableBlockRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
src/main/java/net/frozenblock/lib/block/api/fuel/FuelEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/net/frozenblock/lib/block/mixin/fire/FireBlockMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/net/frozenblock/lib/block/mixin/fuel/AbstractFurnaceBlockEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/net/frozenblock/lib/blockEntity/api/FrozenBlockEntityType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/net/frozenblock/lib/blockEntity/mixin/BlockEntityTypeMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Oops, something went wrong.