Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Akiisqt authored Jan 26, 2024
1 parent 9d6a13b commit 2a2ca82
Show file tree
Hide file tree
Showing 22 changed files with 1,488 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/client/java/com/akiisqt/EntrappedClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.akiisqt;

import net.fabricmc.api.ClientModInitializer;

public class EntrappedClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
}
}
15 changes: 15 additions & 0 deletions src/client/java/com/akiisqt/mixin/client/ExampleClientMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.akiisqt.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 run(CallbackInfo info) {
// This code is injected into the start of MinecraftClient.run()V
}
}
11 changes: 11 additions & 0 deletions src/client/resources/entrapped.client.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"required": true,
"package": "com.akiisqt.mixin.client",
"compatibilityLevel": "JAVA_17",
"client": [
"ExampleClientMixin"
],
"injectors": {
"defaultRequire": 1
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/akiisqt/Entrapped.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.akiisqt;

import net.fabricmc.api.ModInitializer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Entrapped implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("entrapped");
public static final String modId = "entrapped";

@Override
public void onInitialize() {
LOGGER.info("Entrapped - Registering!");

EntrappedBlocks.registerAll();
LOGGER.info("Entrapped - Blocks Registered!");

EntrappedBlockEntities.registerAll();
LOGGER.info("Entrapped - BlocksEntities Registered");

EntrappedItems.registerAll();
LOGGER.info("Entrapped - Items Registered");

LOGGER.info("Entrapped - Fully Loaded!");
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/akiisqt/EntrappedBlockEntities.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.akiisqt;

import com.akiisqt.customblockentity.BarrelEntity;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;

public class EntrappedBlockEntities {
public static BlockEntityType<BarrelEntity> BarrelEntity = FabricBlockEntityTypeBuilder.create(BarrelEntity::new, EntrappedBlocks.blockMap.get("barrel")).build();

public static void registerAll() {
Registry.register(Registries.BLOCK_ENTITY_TYPE, new Identifier("entrapped", "barrel_entity"), BarrelEntity);
}
}


25 changes: 25 additions & 0 deletions src/main/java/com/akiisqt/EntrappedBlocks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.akiisqt;

import com.akiisqt.customblock.Barrel;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;

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

public class EntrappedBlocks {
public static Map<String, Block> blockMap = new HashMap<>();
static {
blockMap.put("barrel", new Barrel(FabricBlockSettings.copy(Blocks.CHERRY_PLANKS)));
}

public static void registerAll() {
for ( var entry: EntrappedBlocks.blockMap.entrySet() ) {
Registry.register(Registries.BLOCK, new Identifier(Entrapped.modId, entry.getKey()), entry.getValue());
}
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/akiisqt/EntrappedDataGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.akiisqt;

import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;

public class EntrappedDataGenerator implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {

}
}
47 changes: 47 additions & 0 deletions src/main/java/com/akiisqt/EntrappedItems.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.akiisqt;

import com.akiisqt.customblock.Barrel;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Blocks;
import net.minecraft.item.*;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

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

public class EntrappedItems {
private static final ItemGroup itemGroup = FabricItemGroup.builder().icon(() -> new ItemStack(Items.TNT)).displayName(Text.translatable("itemGroup.entrapped.main")).build();

public static Map<String, Item> itemMap = new HashMap<>();
static {
itemMap.put("barrel_lid", new Item(new FabricItemSettings()));
}

public static void registerAll() {
Registry.register(Registries.ITEM_GROUP, new Identifier(Entrapped.modId, "main"), itemGroup);

for ( var entry: EntrappedBlocks.blockMap.entrySet() ) {
var Item = Registry.register(Registries.ITEM, new Identifier(Entrapped.modId, entry.getKey()), new BlockItem(entry.getValue(), new FabricItemSettings()));
ItemGroupEvents.modifyEntriesEvent(RegistryKey.of(RegistryKeys.ITEM_GROUP, new Identifier(Entrapped.modId, "main"))).register((entries) ->
{
entries.add(Item);
});
}

for (var entry: itemMap.entrySet() ) {
var Item = Registry.register(Registries.ITEM, new Identifier(Entrapped.modId, entry.getKey()), entry.getValue());
ItemGroupEvents.modifyEntriesEvent(RegistryKey.of(RegistryKeys.ITEM_GROUP, new Identifier(Entrapped.modId, "main"))).register((entries) ->
{
entries.add(Item);
});
}
}
}
67 changes: 67 additions & 0 deletions src/main/java/com/akiisqt/customblock/Barrel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.akiisqt.customblock;

import com.akiisqt.EntrappedItems;
import com.akiisqt.customblockentity.BarrelEntity;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Property;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.function.BooleanBiFunction;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;

import java.util.stream.Stream;

public class Barrel extends HorizontalFacingBlock implements BlockEntityProvider {
private static final VoxelShape shape = Stream.of(
Block.createCuboidShape(2, 0, 14, 14, 16, 15),
Block.createCuboidShape(14, 0, 2, 15, 16, 14),
Block.createCuboidShape(13, 0, 13, 14, 16, 14),
Block.createCuboidShape(13, 0, 2, 14, 16, 3),
Block.createCuboidShape(2, 0, 1, 14, 16, 2),
Block.createCuboidShape(2, 0, 2, 3, 16, 3),
Block.createCuboidShape(1, 0, 2, 2, 16, 14),
Block.createCuboidShape(2, 0, 13, 3, 16, 14),
Block.createCuboidShape(2, 0, 2, 14, 1, 14)
).reduce((v1, v2) -> VoxelShapes.combineAndSimplify(v1, v2, BooleanBiFunction.OR)).get();
public static final IntProperty level = IntProperty.of("level", 0, 8);
public static final BooleanProperty sealed = BooleanProperty.of("sealed");

public Barrel(Settings settings) {
super(settings, shape);
this.setDefaultState(this.getDefaultState().with(level, 0).with(sealed, false));
}

@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new BarrelEntity(pos, state);
}

@Override
@SuppressWarnings("all")
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builderProperties.add(level);
builderProperties.add(sealed);
builder.add(builderProperties.toArray(new Property[]{}));
}

@Override
@SuppressWarnings("deprecation")
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
return ActionResult.SUCCESS;
}

@Override
public boolean shouldDropItemsOnExplosion(Explosion explosion) {
return false;
}
}
55 changes: 55 additions & 0 deletions src/main/java/com/akiisqt/customblock/HorizontalFacingBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.akiisqt.customblock;

import com.akiisqt.util.VoxelShapeRotator;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.*;

public class HorizontalFacingBlock extends Block {
static final DirectionProperty facing = Properties.HORIZONTAL_FACING;
public static final List<Object> builderProperties = new ArrayList<>();
static {
builderProperties.add(facing);
}

final Map<Direction, VoxelShape> shapeMap;

protected HorizontalFacingBlock(AbstractBlock.Settings settings, VoxelShape shape) {
super(settings);
this.shapeMap = VoxelShapeRotator.rotateAllDirections(shape);
this.setDefaultState(this.getDefaultState().with(facing, Direction.NORTH));
}

@Override
public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
if (placer != null) {
world.setBlockState(pos, state.with(facing, placer.getHorizontalFacing()), 2);
}
}

@Override
@SuppressWarnings("deprecation")
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return shapeMap.get(state.get(facing));
}

@Override
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(facing, Direction.fromHorizontal(Math.floorMod((int)Math.floor((double)(Objects.requireNonNull(ctx.getPlayer()).getYaw() * 4.0F / 360.0F) + 0.5D), 4)));
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/akiisqt/customblockentity/BarrelEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.akiisqt.customblockentity;

import com.akiisqt.EntrappedBlockEntities;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;

public class BarrelEntity extends BlockEntity {
public BarrelEntity(BlockPos pos, BlockState state) {
super(EntrappedBlockEntities.BarrelEntity, pos, state);
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/akiisqt/mixin/ExampleMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.akiisqt.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
}
}
Loading

0 comments on commit 2a2ca82

Please sign in to comment.