Skip to content

Commit

Permalink
Port to Fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Oct 8, 2024
1 parent 4f5abf2 commit e1147e6
Show file tree
Hide file tree
Showing 56 changed files with 1,145 additions and 63 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ org.gradle.daemon=false
org.gradle.caching=true

# Common dependencies
cyclopscore_version=1.24.0-620
cyclopscore_version=1.24.0-621
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.LevelWriter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
Expand Down Expand Up @@ -123,4 +125,19 @@ public boolean canSurvive(BlockState blockState, LevelReader world, BlockPos blo
return super.canSurvive(blockState, world, blockPos) && ColossalChest.canPlace(world, blockPos);
}

public void onBlockExplodedCommon(BlockState state, Level world, BlockPos pos, Explosion explosion) {
if(world.getBlockState(pos).getValue(ENABLED)) ColossalChest.triggerDetector(material, world, pos, false, null);
// IForgeBlock.super.onBlockExploded(state, world, pos, explosion);
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
wasExploded(world, pos, explosion);
}

@Override
public float getExplosionResistance() {
if (this.material.isExplosionResistant()) {
return 10000F;
}
return 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.LevelWriter;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
Expand All @@ -45,6 +47,7 @@
import org.cyclops.cyclopscore.block.multi.DetectionResult;
import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntityCommon;
import org.cyclops.cyclopscore.datastructure.Wrapper;
import org.cyclops.cyclopscore.helper.IBlockEntityHelpers;
import org.cyclops.cyclopscore.helper.IModHelpers;
import org.cyclops.cyclopscore.inventory.SimpleInventoryCommon;
import org.spongepowered.asm.mixin.Interface;
Expand Down Expand Up @@ -253,7 +256,10 @@ public static void addPlayerChatError(Player player, Component error) {

@Override
public void writeExtraGuiData(FriendlyByteBuf packetBuffer, Level world, Player player, BlockPos blockPos, BlockHitResult rayTraceResult) {
IModHelpers.get().getBlockEntityHelpers().get(world, blockPos, BlockEntityColossalChest.class).ifPresent(tile -> packetBuffer.writeInt(tile.getInventory().getContainerSize()));
IBlockEntityHelpers blockEntityHelpers = IModHelpers.get().getBlockEntityHelpers();
blockEntityHelpers.setUnsafeBlockEntityGetter(true); // Required for Fabric as this is called on the network thread
blockEntityHelpers.get(world, blockPos, BlockEntityColossalChest.class).ifPresent(tile -> packetBuffer.writeInt(tile.getInventory().getContainerSize()));
blockEntityHelpers.setUnsafeBlockEntityGetter(false); // Required for Fabric as this is called on the network thread
}

@Override
Expand Down Expand Up @@ -289,6 +295,21 @@ public void onRemove(BlockState oldState, Level world, BlockPos blockPos, BlockS
}
}

public void onBlockExplodedCommon(BlockState state, Level world, BlockPos pos, Explosion explosion) {
if(world.getBlockState(pos).getValue(ENABLED)) ColossalChest.triggerDetector(material, world, pos, false, null);
// IForgeBlock.super.onBlockExploded(state, world, pos, explosion);
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
wasExploded(world, pos, explosion);
}

@Override
public float getExplosionResistance() {
if (this.material.isExplosionResistant()) {
return 10000F;
}
return 0;
}

private static class MaterialValidationAction implements CubeDetector.IValidationAction {
private final Wrapper<ChestMaterial> requiredMaterial;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.LevelWriter;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
Expand Down Expand Up @@ -127,6 +129,21 @@ public void onDetect(LevelReader world, BlockPos location, Vec3i size, boolean v
}
}

public void onBlockExplodedCommon(BlockState state, Level world, BlockPos pos, Explosion explosion) {
if(world.getBlockState(pos).getValue(ENABLED)) ColossalChest.triggerDetector(material, world, pos, false, null);
// IForgeBlock.super.onBlockExploded(state, world, pos, explosion);
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
wasExploded(world, pos, explosion);
}

@Override
public float getExplosionResistance() {
if (this.material.isExplosionResistant()) {
return 10000F;
}
return 0;
}

@Override
public InteractionResult useWithoutItem(BlockState blockState, Level world, BlockPos blockPos, Player player, BlockHitResult rayTraceResult) {
if(blockState.getValue(ENABLED)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ protected BlockEntityRendererProvider<BlockEntityColossalChest> getBlockEntityRe
}

@Override
public void onRegistered() {
super.onRegistered();
public void onForgeRegistered() {
super.onForgeRegistered();
if (getMod().getModHelpers().getMinecraftHelpers().isClientSide()) {
getMod().getProxy().registerRenderer(getInstance(), getBlockEntityRendererProvider());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public BlockEntityUncolossalChestConfig(M mod) {
}

@Override
public void onRegistered() {
super.onRegistered();
public void onForgeRegistered() {
super.onForgeRegistered();
if (getMod().getModHelpers().getMinecraftHelpers().isClientSide()) {
getMod().getProxy().registerRenderer(getInstance(), RenderTileEntityUncolossalChest::new);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cyclops.colossalchests.inventory.container;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.Container;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.player.Inventory;
Expand All @@ -11,7 +12,7 @@
*/
public class ContainerUncolossalChest extends InventoryContainerCommon {

public ContainerUncolossalChest(int id, Inventory playerInventory) {
public ContainerUncolossalChest(int id, Inventory playerInventory, FriendlyByteBuf buf) {
this(id, playerInventory, new SimpleContainer(5));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.cyclops.colossalchests.inventory.container;

import net.minecraft.world.flag.FeatureFlags;
import net.minecraft.world.inventory.MenuType;
import org.cyclops.cyclopscore.config.extendedconfig.GuiConfigCommon;
import org.cyclops.cyclopscore.config.extendedconfig.GuiConfigScreenFactoryProvider;
import org.cyclops.cyclopscore.init.IModBase;
import org.cyclops.cyclopscore.inventory.container.ContainerTypeDataCommon;

/**
* Config for {@link ContainerUncolossalChest}.
Expand All @@ -15,7 +15,7 @@ public class ContainerUncolossalChestConfig<M extends IModBase> extends GuiConfi
public ContainerUncolossalChestConfig(M mod) {
super(mod,
"uncolossal_chest",
eConfig -> new MenuType<>(ContainerUncolossalChest::new, FeatureFlags.VANILLA_SET));
eConfig -> new ContainerTypeDataCommon<>(ContainerUncolossalChest::new, FeatureFlags.VANILLA_SET));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.cyclops.colossalchests;

import net.fabricmc.api.ModInitializer;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import org.cyclops.colossalchests.advancement.criterion.ChestFormedTriggerConfig;
import org.cyclops.colossalchests.block.ChestMaterial;
import org.cyclops.colossalchests.block.ChestWallConfigFabric;
import org.cyclops.colossalchests.block.ColossalChestConfigFabric;
import org.cyclops.colossalchests.block.InterfaceConfigFabric;
import org.cyclops.colossalchests.block.UncolossalChestConfigFabric;
import org.cyclops.colossalchests.blockentity.BlockEntityColossalChestConfigFabric;
import org.cyclops.colossalchests.blockentity.BlockEntityInterfaceConfigFabric;
import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChestConfigFabric;
import org.cyclops.colossalchests.condition.ConditionMetalVariantsSettingConfig;
import org.cyclops.colossalchests.inventory.container.ContainerColossalChestConfig;
import org.cyclops.colossalchests.inventory.container.ContainerUncolossalChestConfig;
import org.cyclops.colossalchests.item.ItemUpgradeToolConfig;
import org.cyclops.colossalchests.proxy.ClientProxyFabric;
import org.cyclops.colossalchests.proxy.CommonProxyFabric;
import org.cyclops.cyclopscore.config.ConfigHandlerCommon;
import org.cyclops.cyclopscore.init.ModBaseFabric;
import org.cyclops.cyclopscore.proxy.IClientProxyCommon;
import org.cyclops.cyclopscore.proxy.ICommonProxyCommon;

/**
* The main mod class of ColossalChests.
* @author rubensworks
*/
public class ColossalChestsFabric extends ModBaseFabric<ColossalChestsFabric> implements ModInitializer {

/**
* The unique instance of this mod.
*/
public static ColossalChestsFabric _instance;

public ColossalChestsFabric() {
super(Reference.MOD_ID, (instance) -> {
ColossalChestsInstance.MOD = instance;
_instance = instance;
});
}

@Override
protected IClientProxyCommon constructClientProxy() {
return new ClientProxyFabric();
}

@Override
protected ICommonProxyCommon constructCommonProxy() {
return new CommonProxyFabric();
}

@Override
protected boolean hasDefaultCreativeModeTab() {
return true;
}

@Override
protected CreativeModeTab.Builder constructDefaultCreativeModeTab(CreativeModeTab.Builder builder) {
return super.constructDefaultCreativeModeTab(builder)
.icon(() -> new ItemStack(RegistryEntries.ITEM_CHEST));
}

@Override
protected void onConfigsRegister(ConfigHandlerCommon configHandler) {
super.onConfigsRegister(configHandler);

configHandler.addConfigurable(new GeneralConfig<>(this));

for (ChestMaterial material : ChestMaterial.VALUES) {
configHandler.addConfigurable(new ChestWallConfigFabric<>(this, material));
configHandler.addConfigurable(new ColossalChestConfigFabric<>(this, material));
configHandler.addConfigurable(new InterfaceConfigFabric<>(this, material));
}
configHandler.addConfigurable(new UncolossalChestConfigFabric<>(this));

configHandler.addConfigurable(new ItemUpgradeToolConfig<>(this, true));
configHandler.addConfigurable(new ItemUpgradeToolConfig<>(this, false));

configHandler.addConfigurable(new BlockEntityColossalChestConfigFabric<>(this));
configHandler.addConfigurable(new BlockEntityInterfaceConfigFabric<>(this));
configHandler.addConfigurable(new BlockEntityUncolossalChestConfigFabric<>(this));

configHandler.addConfigurable(new ContainerColossalChestConfig<>(this));
configHandler.addConfigurable(new ContainerUncolossalChestConfig<>(this));

configHandler.addConfigurable(new ConditionMetalVariantsSettingConfig());

configHandler.addConfigurable(new ChestFormedTriggerConfig<>(this));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.cyclops.colossalchests.block;

import net.minecraft.world.item.Item;
import org.cyclops.colossalchests.item.ItemBlockMaterial;
import org.cyclops.cyclopscore.init.IModBase;

/**
* Config for the {@link ChestWall}.
* @author rubensworks
*
*/
public class ChestWallConfigFabric<M extends IModBase> extends ChestWallConfig<M> {

public ChestWallConfigFabric(M mod, ChestMaterial material) {
super(
mod,
"chest_wall_" + material.getName(),
eConfig -> new ChestWallFabric(((ChestWallConfig<M>) eConfig).getProperties(), material),
(eConfig, block) -> new ItemBlockMaterial(block, new Item.Properties(), material)
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.cyclops.colossalchests.block;

import net.minecraft.world.level.Level;
import org.cyclops.cyclopscore.events.IBlockExplodedEvent;

/**
* @author rubensworks
*/
public class ChestWallFabric extends ChestWall {
public ChestWallFabric(Properties properties, ChestMaterial material) {
super(properties, material);
IBlockExplodedEvent.EVENT.register((blockState, level, blockPos, explosion, biConsumer) -> onBlockExplodedCommon(blockState, level, blockPos, explosion));
}

@Override
protected boolean isCaptureBlockSnapshots(Level level) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.cyclops.colossalchests.block;

import net.minecraft.world.item.Item;
import org.cyclops.colossalchests.item.ItemBlockMaterial;
import org.cyclops.cyclopscore.init.IModBase;

/**
* Config for the {@link ColossalChest}.
* @author rubensworks
*
*/
public class ColossalChestConfigFabric<M extends IModBase> extends ColossalChestConfig<M> {

public ColossalChestConfigFabric(M mod, ChestMaterial material) {
super(
mod,
"colossal_chest_" + material.getName(),
eConfig -> new ColossalChestFabric(((ColossalChestConfig<M>) eConfig).getProperties(), material),
(eConfig, block) -> new ItemBlockMaterial(block, new Item.Properties(), material)
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.cyclops.colossalchests.block;

import net.minecraft.world.level.Level;
import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest;
import org.cyclops.cyclopscore.events.IBlockExplodedEvent;

/**
* @author rubensworks
*/
public class ColossalChestFabric extends ColossalChest {
public ColossalChestFabric(Properties properties, ChestMaterial material) {
super(properties, material, BlockEntityColossalChest::new);
IBlockExplodedEvent.EVENT.register((blockState, level, blockPos, explosion, biConsumer) -> onBlockExplodedCommon(blockState, level, blockPos, explosion));
}

@Override
protected boolean isCaptureBlockSnapshots(Level level) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.cyclops.colossalchests.block;

import net.minecraft.world.item.Item;
import org.cyclops.colossalchests.item.ItemBlockMaterial;
import org.cyclops.cyclopscore.init.IModBase;

/**
* Config for the {@link Interface}.
* @author rubensworks
*
*/
public class InterfaceConfigFabric<M extends IModBase> extends InterfaceConfig<M> {

public InterfaceConfigFabric(M mod, ChestMaterial material) {
super(
mod,
"interface_" + material.getName(),
eConfig -> new InterfaceFabric(((InterfaceConfig<M>) eConfig).getProperties(), material),
(eConfig, block) -> new ItemBlockMaterial(block, new Item.Properties(), material)
);
}

}
Loading

0 comments on commit e1147e6

Please sign in to comment.