diff options
author | Linnea Gräf <nea@nea.moe> | 2024-11-20 17:56:18 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-11-20 17:56:18 +0100 |
commit | 241682c95b56f47cbd09f79dd77c6ad8ee4489c5 (patch) | |
tree | 8f00327c842bd8ab01280a8ad6ef0724b1f12f01 /src | |
download | funny-teleporters-241682c95b56f47cbd09f79dd77c6ad8ee4489c5.tar.gz funny-teleporters-241682c95b56f47cbd09f79dd77c6ad8ee4489c5.tar.bz2 funny-teleporters-241682c95b56f47cbd09f79dd77c6ad8ee4489c5.zip |
Init
Diffstat (limited to 'src')
11 files changed, 284 insertions, 0 deletions
diff --git a/src/client/java/moe/nea/funnyteleporters/FunnyTeleportersClient.java b/src/client/java/moe/nea/funnyteleporters/FunnyTeleportersClient.java new file mode 100644 index 0000000..1b81705 --- /dev/null +++ b/src/client/java/moe/nea/funnyteleporters/FunnyTeleportersClient.java @@ -0,0 +1,10 @@ +package moe.nea.funnyteleporters; + +import net.fabricmc.api.ClientModInitializer; + +public class FunnyTeleportersClient implements ClientModInitializer { + @Override + public void onInitializeClient() { + // This entrypoint is suitable for setting up client-specific logic, such as rendering. + } +}
\ No newline at end of file diff --git a/src/client/java/moe/nea/funnyteleporters/mixin/client/ExampleClientMixin.java b/src/client/java/moe/nea/funnyteleporters/mixin/client/ExampleClientMixin.java new file mode 100644 index 0000000..33e28f5 --- /dev/null +++ b/src/client/java/moe/nea/funnyteleporters/mixin/client/ExampleClientMixin.java @@ -0,0 +1,15 @@ +package moe.nea.funnyteleporters.mixin.client; + +import net.minecraft.client.MinecraftClient; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(MinecraftClient.class) +public class ExampleClientMixin { + @Inject(at = @At("HEAD"), method = "run") + private void init(CallbackInfo info) { + // This code is injected into the start of MinecraftClient.run()V + } +}
\ No newline at end of file diff --git a/src/client/resources/funny-teleporters.client.mixins.json b/src/client/resources/funny-teleporters.client.mixins.json new file mode 100644 index 0000000..08beeb6 --- /dev/null +++ b/src/client/resources/funny-teleporters.client.mixins.json @@ -0,0 +1,11 @@ +{ + "required": true, + "package": "moe.nea.funnyteleporters.mixin.client", + "compatibilityLevel": "JAVA_21", + "client": [ + "ExampleClientMixin" + ], + "injectors": { + "defaultRequire": 1 + } +}
\ No newline at end of file diff --git a/src/main/java/moe/nea/funnyteleporters/ColouredChestBlock.java b/src/main/java/moe/nea/funnyteleporters/ColouredChestBlock.java new file mode 100644 index 0000000..eb68f95 --- /dev/null +++ b/src/main/java/moe/nea/funnyteleporters/ColouredChestBlock.java @@ -0,0 +1,113 @@ +package moe.nea.funnyteleporters; + +import com.mojang.serialization.MapCodec; +import eu.pb4.polymer.core.api.block.PolymerBlock; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.AbstractChestBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.ChestBlock; +import net.minecraft.block.DoubleBlockProperties; +import net.minecraft.block.EnderChestBlock; +import net.minecraft.block.FacingBlock; +import net.minecraft.block.HorizontalFacingBlock; +import net.minecraft.block.Waterloggable; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.ChestBlockEntity; +import net.minecraft.entity.ai.pathing.NavigationType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.Properties; +import net.minecraft.state.property.Property; +import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; + +public class ColouredChestBlock extends AbstractChestBlock<ColouredChestBlockEntity> implements PolymerBlock, Waterloggable { + static Property<Direction> FACING = HorizontalFacingBlock.FACING; + static Property<Boolean> WATERLOGGED = Properties.WATERLOGGED; + + public ColouredChestBlock(Settings settings) { + super(settings, () -> FunnyRegistry.COLOURED_CHEST_ENTITY); + setDefaultState(getStateManager() + .getDefaultState() + .with(FACING, Direction.NORTH) + .with(WATERLOGGED, false)); + } + + @Override + public BlockState getPolymerBlockState(BlockState blockState) { + return Blocks.CHEST.getStateWithProperties(blockState); + } + + @Override + public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return new ColouredChestBlockEntity(pos, state); + } + + @Override + public BlockState getPlacementState(ItemPlacementContext ctx) { + return getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite()).with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER); + } + + @Override + protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { + // TODO: create a ui or something to configure frequency + player.sendMessage(Text.literal("Ender Chest geöffnet" + player)); + return super.onUse(state, world, pos, player, hit); + } + + @Override + protected BlockState rotate(BlockState state, BlockRotation rotation) { + return state.with(FACING, rotation.rotate(state.get(FACING))); + } + + @Override + protected BlockState mirror(BlockState state, BlockMirror mirror) { + return state.rotate(mirror.getRotation(state.get(FACING))); + } + + @Override + protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { + builder.add(FACING, WATERLOGGED); + } + + @Override + protected FluidState getFluidState(BlockState state) { + return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); + } + + @Override + protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { + if (state.get(WATERLOGGED)) + world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); + return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos); + } + + @Override + protected boolean canPathfindThrough(BlockState state, NavigationType type) { + return false; + } + + static final MapCodec<ColouredChestBlock> CODEC = createCodec(ColouredChestBlock::new); + + @Override + protected MapCodec<? extends AbstractChestBlock<ColouredChestBlockEntity>> getCodec() { + return CODEC; + } + + @Override + public DoubleBlockProperties.PropertySource<? extends ChestBlockEntity> getBlockEntitySource(BlockState state, World world, BlockPos pos, boolean ignoreBlocked) { + return DoubleBlockProperties.PropertyRetriever::getFallback; + } +} diff --git a/src/main/java/moe/nea/funnyteleporters/ColouredChestBlockEntity.java b/src/main/java/moe/nea/funnyteleporters/ColouredChestBlockEntity.java new file mode 100644 index 0000000..e26aea1 --- /dev/null +++ b/src/main/java/moe/nea/funnyteleporters/ColouredChestBlockEntity.java @@ -0,0 +1,17 @@ +package moe.nea.funnyteleporters; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.block.entity.ChestBlockEntity; +import net.minecraft.util.math.BlockPos; + +public class ColouredChestBlockEntity extends ChestBlockEntity { + public ColouredChestBlockEntity(BlockPos blockPos, BlockState blockState) { + this(FunnyRegistry.COLOURED_CHEST_ENTITY, blockPos, blockState); + } + + protected ColouredChestBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) { + super(blockEntityType, blockPos, blockState); + } +} diff --git a/src/main/java/moe/nea/funnyteleporters/FunnyRegistry.java b/src/main/java/moe/nea/funnyteleporters/FunnyRegistry.java new file mode 100644 index 0000000..0297425 --- /dev/null +++ b/src/main/java/moe/nea/funnyteleporters/FunnyRegistry.java @@ -0,0 +1,34 @@ +package moe.nea.funnyteleporters; + +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.util.Identifier; + +public class FunnyRegistry { + public static Block COLOURED_CHEST = registerBlock("coloured_chest", new ColouredChestBlock(AbstractBlock.Settings.create())); + public static BlockEntityType<ColouredChestBlockEntity> COLOURED_CHEST_ENTITY = registerBlockEntity("coloured_chest", BlockEntityType.Builder.create(ColouredChestBlockEntity::new, COLOURED_CHEST)); + + + private static <T extends BlockEntity> BlockEntityType<T> registerBlockEntity(String name, BlockEntityType.Builder<T> builder, Block... blocks) { + return Registry.register(Registries.BLOCK_ENTITY_TYPE, + Identifier.of("funny_teleporters", name), + builder.build() + ); + } + + private static <T extends Block> T registerBlock(String name, T block) { + var id = Identifier.of("funny_teleporters", name); + Registry.register(Registries.ITEM, id, new BlockItem(block, new Item.Settings())); + return Registry.register(Registries.BLOCK, id, block); + } + + public static void init() { + + } +} diff --git a/src/main/java/moe/nea/funnyteleporters/FunnyTeleporters.java b/src/main/java/moe/nea/funnyteleporters/FunnyTeleporters.java new file mode 100644 index 0000000..eb4accb --- /dev/null +++ b/src/main/java/moe/nea/funnyteleporters/FunnyTeleporters.java @@ -0,0 +1,17 @@ +package moe.nea.funnyteleporters; + +import net.fabricmc.api.ModInitializer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class FunnyTeleporters implements ModInitializer { + public static final String MOD_ID = "funny-teleporters"; + + public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + + @Override + public void onInitialize() { + FunnyRegistry.init(); + } +}
\ No newline at end of file diff --git a/src/main/java/moe/nea/funnyteleporters/mixin/ExampleMixin.java b/src/main/java/moe/nea/funnyteleporters/mixin/ExampleMixin.java new file mode 100644 index 0000000..082f20b --- /dev/null +++ b/src/main/java/moe/nea/funnyteleporters/mixin/ExampleMixin.java @@ -0,0 +1,15 @@ +package moe.nea.funnyteleporters.mixin; + +import net.minecraft.server.MinecraftServer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(MinecraftServer.class) +public class ExampleMixin { + @Inject(at = @At("HEAD"), method = "loadWorld") + private void init(CallbackInfo info) { + // This code is injected into the start of MinecraftServer.loadWorld()V + } +}
\ No newline at end of file diff --git a/src/main/resources/assets/funny-teleporters/icon.png b/src/main/resources/assets/funny-teleporters/icon.png Binary files differnew file mode 100644 index 0000000..71d4949 --- /dev/null +++ b/src/main/resources/assets/funny-teleporters/icon.png diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..4f92431 --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,41 @@ +{ + "schemaVersion": 1, + "id": "funny-teleporters", + "version": "${version}", + "name": "Funny Teleporters", + "description": "This is an example description! Tell everyone what your mod is about!", + "authors": [ + "Me!" + ], + "contact": { + "homepage": "https://fabricmc.net/", + "sources": "https://github.com/FabricMC/fabric-example-mod" + }, + "license": "CC0-1.0", + "icon": "assets/funny-teleporters/icon.png", + "environment": "*", + "entrypoints": { + "main": [ + "moe.nea.funnyteleporters.FunnyTeleporters" + ], + "client": [ + "moe.nea.funnyteleporters.FunnyTeleportersClient" + ] + }, + "mixins": [ + "funny-teleporters.mixins.json", + { + "config": "funny-teleporters.client.mixins.json", + "environment": "client" + } + ], + "depends": { + "fabricloader": ">=0.16.9", + "minecraft": "~1.21", + "java": ">=21", + "fabric-api": "*" + }, + "suggests": { + "another-mod": "*" + } +}
\ No newline at end of file diff --git a/src/main/resources/funny-teleporters.mixins.json b/src/main/resources/funny-teleporters.mixins.json new file mode 100644 index 0000000..1b0964e --- /dev/null +++ b/src/main/resources/funny-teleporters.mixins.json @@ -0,0 +1,11 @@ +{ + "required": true, + "package": "moe.nea.funnyteleporters.mixin", + "compatibilityLevel": "JAVA_21", + "mixins": [ + "ExampleMixin" + ], + "injectors": { + "defaultRequire": 1 + } +}
\ No newline at end of file |