-
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
19 changed files
with
1,688 additions
and
0 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
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
15
src/client/java/com/akiisqt/mixin/client/ExampleClientMixin.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,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 | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"required": true, | ||
"package": "com.akiisqt.mixin.client", | ||
"compatibilityLevel": "JAVA_17", | ||
"client": [ | ||
"ExampleClientMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |
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 com.akiisqt; | ||
|
||
import net.fabricmc.api.ModInitializer; | ||
|
||
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.minecraft.item.BlockItem; | ||
import net.minecraft.item.ItemGroup; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
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 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"; | ||
private static final ItemGroup itemGroup = FabricItemGroup.builder() | ||
.icon(() -> new ItemStack(Items.TNT)) | ||
.displayName(Text.translatable("itemGroup.entrapped.main")) | ||
.build(); | ||
|
||
@Override | ||
public void onInitialize() { | ||
Registry.register(Registries.ITEM_GROUP, new Identifier(ModId, "main"), itemGroup); | ||
|
||
for ( var Entry: EntrappedBlocks.blockMap.entrySet() ) { | ||
var Item = Registry.register(Registries.ITEM, new Identifier(ModId, Entry.getKey()), new BlockItem(Entry.getValue(), new FabricItemSettings())); | ||
ItemGroupEvents.modifyEntriesEvent(RegistryKey.of(RegistryKeys.ITEM_GROUP, new Identifier(ModId, "main"))).register((entries) -> | ||
{ | ||
entries.add(Item); | ||
}); | ||
|
||
EntrappedBlocks.blockMap.replace(Entry.getKey(), Registry.register(Registries.BLOCK, new Identifier(ModId, Entry.getKey().toLowerCase()), Entry.getValue())); | ||
} | ||
|
||
LOGGER.info("Entrapped Loaded!"); | ||
} | ||
} |
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,44 @@ | ||
package com.akiisqt; | ||
|
||
import com.akiisqt.customblocks.Barrel; | ||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.block.ShapeContext; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
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.BlockView; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
|
||
public class EntrappedBlocks { | ||
|
||
//public static Map<String, HashMap<Block, String>> blockMap = new HashMap<>(); | ||
public static Map<String, Block> blockMap = new HashMap<>(); | ||
static { | ||
//setValuesOfKey(blockMap, "gunpowder_barrel", new Barrel(FabricBlockSettings.create()), "yo"); | ||
blockMap.put("gunpowder_barrel", new Barrel(FabricBlockSettings.copy(Blocks.CHERRY_PLANKS))); | ||
} | ||
// public static void setValuesOfKey(Map<String, HashMap<Block, String>> map, String key, Block block, String string) { | ||
// // Get the inner map for the specified key | ||
// HashMap<Block, String> innerMap = map.getOrDefault(key, new HashMap<>()); | ||
// | ||
// // Set the value for the provided Block in the inner map | ||
// innerMap.put(block, string); | ||
// | ||
// // Put the updated inner map back into the outer map | ||
// map.put(key, innerMap); | ||
// } | ||
} |
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,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) { | ||
|
||
} | ||
} |
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,40 @@ | ||
package com.akiisqt.customblocks; | ||
|
||
import net.minecraft.block.AbstractBlock; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.ShapeContext; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
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.BlockView; | ||
import net.minecraft.world.World; | ||
|
||
import java.awt.*; | ||
import java.util.stream.Stream; | ||
|
||
public class Barrel extends Template { | ||
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) { | ||
return VoxelShapes.cuboid(0.1f, 0.0f, 0.1f, 0.9f, 1.0f, 0.9f); | ||
} | ||
private static final VoxelShape shape = Stream.of( | ||
Block.createCuboidShape(4, 0, 2, 12, 12, 14), | ||
Block.createCuboidShape(7, 13, 1, 9, 19, 3), | ||
Block.createCuboidShape(6, 12, 0, 10, 14, 4), | ||
Block.createCuboidShape(6, 11, 11, 10, 13, 13), | ||
Block.createCuboidShape(6, 13, 5, 10, 14, 13), | ||
Block.createCuboidShape(6, 11, 5, 10, 13, 7) | ||
).reduce((v1, v2) -> VoxelShapes.combineAndSimplify(v1, v2, BooleanBiFunction.OR)).get(); | ||
public Barrel(AbstractBlock.Settings settings) { | ||
super(settings); | ||
} | ||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player2, Hand hand, BlockHitResult hit) { | ||
|
||
return ActionResult.SUCCESS; | ||
} | ||
} |
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,68 @@ | ||
package com.akiisqt.customblocks; | ||
|
||
import com.akiisqt.util.VoxelShapeRotator; | ||
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.StateManager; | ||
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.Map; | ||
import java.util.Objects; | ||
|
||
public abstract class Template extends Block { | ||
final VoxelShape NORTH_SHAPE; | ||
final Map<Direction, VoxelShape> SHAPE_MAP; | ||
|
||
public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING; | ||
|
||
public Template(Settings settings, VoxelShape SHAPE) { | ||
super(settings); | ||
this.NORTH_SHAPE = SHAPE; | ||
this.SHAPE_MAP = VoxelShapeRotator.rotateAllDirections(NORTH_SHAPE); | ||
} | ||
public Template(Settings settings) { | ||
super(settings); | ||
this.NORTH_SHAPE = null; | ||
this.SHAPE_MAP = null; | ||
} | ||
|
||
|
||
@Override | ||
public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) { | ||
if (placer != null) { | ||
Direction direction = placer.getHorizontalFacing(); | ||
world.setBlockState(pos, state.with(FACING, direction), 2); | ||
} | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("deprecation") | ||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { | ||
Direction facing = state.get(FACING); | ||
return SHAPE_MAP.get(facing); | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { | ||
builder.add(FACING); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
float yaw = Objects.requireNonNull(ctx.getPlayer()).getYaw(); | ||
Direction dir = Direction.fromHorizontal(Math.floorMod((int)Math.floor((double)(yaw * 4.0F / 360.0F) + 0.5D), 4)); | ||
return this.getDefaultState().with(FACING, dir); | ||
} | ||
} |
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,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 | ||
} | ||
} |
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,101 @@ | ||
package com.akiisqt.util; | ||
|
||
import net.minecraft.util.math.Box; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.shape.VoxelShape; | ||
import net.minecraft.util.shape.VoxelShapes; | ||
|
||
import java.util.EnumMap; | ||
import java.util.Map; | ||
|
||
public class VoxelShapeRotator { | ||
|
||
// Existing method | ||
public static Map<Direction, VoxelShape> rotateAllDirections(VoxelShape originalShape) { | ||
Map<Direction, VoxelShape> rotatedShapes = new EnumMap<>(Direction.class); | ||
|
||
rotatedShapes.put(Direction.NORTH, originalShape); | ||
rotatedShapes.put(Direction.EAST, rotate90Degrees(originalShape)); | ||
rotatedShapes.put(Direction.SOUTH, rotate180Degrees(originalShape)); | ||
rotatedShapes.put(Direction.WEST, rotate270Degrees(originalShape)); | ||
|
||
return rotatedShapes; | ||
} | ||
|
||
/** | ||
* Rotates the given VoxelShape 90 degrees clockwise. | ||
* | ||
* @param originalShape The original VoxelShape to rotate. | ||
* @return The rotated VoxelShape. | ||
*/ | ||
public static VoxelShape rotate90Degrees(VoxelShape originalShape) { | ||
return rotate(originalShape, 0.5, 0.5, 0.5, 90); | ||
} | ||
|
||
/** | ||
* Rotates the given VoxelShape 180 degrees. | ||
* | ||
* @param originalShape The original VoxelShape to rotate. | ||
* @return The rotated VoxelShape. | ||
*/ | ||
public static VoxelShape rotate180Degrees(VoxelShape originalShape) { | ||
return rotate(originalShape, 0.5, 0.5, 0.5, 180); | ||
} | ||
|
||
/** | ||
* Rotates the given VoxelShape 270 degrees clockwise. | ||
* | ||
* @param originalShape The original VoxelShape to rotate. | ||
* @return The rotated VoxelShape. | ||
*/ | ||
public static VoxelShape rotate270Degrees(VoxelShape originalShape) { | ||
return rotate(originalShape, 0.5, 0.5, 0.5, 270); | ||
} | ||
|
||
/** | ||
* Rotates the given VoxelShape around the specified point by the given angle. | ||
* | ||
* @param originalShape The original VoxelShape to rotate. | ||
* @param centerX The x-coordinate of the rotation center. | ||
* @param centerY The y-coordinate of the rotation center. | ||
* @param centerZ The z-coordinate of the rotation center. | ||
* @param angle The rotation angle in degrees. | ||
* @return The rotated VoxelShape. | ||
*/ | ||
public static VoxelShape rotate(VoxelShape originalShape, double centerX, double centerY, double centerZ, double angle) { | ||
VoxelShape rotatedShape = VoxelShapes.empty(); | ||
|
||
// Loop through the boxes in the original shape | ||
for (Box box : originalShape.getBoundingBoxes()) { | ||
// Rotate the box | ||
Box rotatedBox = rotateBox(box, centerX, centerY, centerZ, angle); | ||
// Combine the rotated box into the final shape | ||
rotatedShape = VoxelShapes.union(rotatedShape, VoxelShapes.cuboid(rotatedBox)); | ||
} | ||
|
||
return rotatedShape; | ||
} | ||
|
||
/** | ||
* Rotates the given Box around the specified point by the given angle. | ||
* | ||
* @param box The original Box to rotate. | ||
* @param centerX The x-coordinate of the rotation center. | ||
* @param centerY The y-coordinate of the rotation center. | ||
* @param centerZ The z-coordinate of the rotation center. | ||
* @param angle The rotation angle in degrees. | ||
* @return The rotated Box. | ||
*/ | ||
public static Box rotateBox(Box box, double centerX, double centerY, double centerZ, double angle) { | ||
double rad = Math.toRadians(angle); | ||
|
||
// The Y coordinate is unchanged, only X and Z are affected by rotation | ||
double minX = Math.cos(rad) * (box.minX - centerX) - Math.sin(rad) * (box.minZ - centerZ) + centerX; | ||
double minZ = Math.sin(rad) * (box.minX - centerX) + Math.cos(rad) * (box.minZ - centerZ) + centerZ; | ||
double maxX = Math.cos(rad) * (box.maxX - centerX) - Math.sin(rad) * (box.maxZ - centerZ) + centerX; | ||
double maxZ = Math.sin(rad) * (box.maxX - centerX) + Math.cos(rad) * (box.maxZ - centerZ) + centerZ; | ||
|
||
return new Box(Math.min(minX, maxX), box.minY, Math.min(minZ, maxZ), | ||
Math.max(minX, maxX), box.maxY, Math.max(minZ, maxZ)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/resources/assets/entrapped/blockstates/gunpowder_barrel.json
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,20 @@ | ||
{ | ||
"type": "minecraft:block", | ||
"pools": [ | ||
{ | ||
"rolls": 1, | ||
"entries": [ | ||
{ | ||
"type": "minecraft:item", | ||
"name": "entrapped:example_block" | ||
} | ||
] | ||
} | ||
], | ||
"variants": { | ||
"facing=east": {"model": "entrapped:block/gunpowder_barrel", "y": 270}, | ||
"facing=north": {"model": "entrapped:block/gunpowder_barrel", "y": 180}, | ||
"facing=south": {"model": "entrapped:block/gunpowder_barrel"}, | ||
"facing=west": {"model": "entrapped:block/gunpowder_barrel", "y": 90} | ||
} | ||
} |
Empty file.
Oops, something went wrong.