Merge pull request #9 from dragonruler1000/DEV

Added a window block and working on portal stuff.
This commit is contained in:
dragonruler1000 2025-05-13 16:59:25 -05:00 committed by GitHub
commit 572719fd30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 230 additions and 76 deletions

View file

@ -120,11 +120,6 @@ dependencies {
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
// Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}")
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-forge-api:${jei_version}")
// runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}-forge:${jei_version}")
// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar

View file

@ -19,6 +19,7 @@ import java.util.function.ToIntFunction;
public class ModBlocks {
public static ToIntFunction<BlockState> dustLightLevel = BlockState -> 10; // Dust Light Level
public static ToIntFunction<BlockState> PORTAL_LIGHT_LEVEL = BlockState ->15;
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Hdm_mod.MOD_ID);
@ -26,6 +27,10 @@ public class ModBlocks {
() -> new Block(AbstractBlock.Properties.create(Material.ROCK).doesNotBlockMovement().harvestLevel(0)
.hardnessAndResistance(500f, 100f).setLightLevel(dustLightLevel)));
public static final RegistryObject<Block> PORTAL_BLOCK = registerBlock("window",
() -> new Block(AbstractBlock.Properties.create(Material.PORTAL).doesNotBlockMovement().harvestLevel(10)
.hardnessAndResistance(1000f, 1000f).setLightLevel(PORTAL_LIGHT_LEVEL)));
private static <T extends Block>RegistryObject<T> registerBlock(String name, Supplier<T> block) {
RegistryObject<T> toReturn = BLOCKS.register(name, block);

View file

@ -0,0 +1,129 @@
package us.minecraftchest2.hdm_mod.block.custom;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.server.MinecraftServer;
import net.minecraft.state.StateContainer;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.shapes.IBooleanFunction;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import us.minecraftchest2.hdm_mod.world.dimension.ModDimensions;
import us.minecraftchest2.hdm_mod.world.dimension.SimpleTeleporter;
import javax.annotation.Nullable;
import java.util.stream.Stream;
public class Window extends HorizontalBlock {
public Window(Properties builder) {
super(builder);
}
private static final VoxelShape SHAPE_N = Stream.of(
Block.makeCuboidShape(5, 11, 5, 6, 13, 11),
Block.makeCuboidShape(4, 0, 4, 12, 1, 12),
Block.makeCuboidShape(5, 1, 5, 11, 2, 11),
Block.makeCuboidShape(6, 2, 6, 10, 10, 10),
Block.makeCuboidShape(5, 10, 4, 11, 11, 12),
Block.makeCuboidShape(5, 11, 4, 11, 12, 5),
Block.makeCuboidShape(5, 11, 11, 11, 14, 12),
Block.makeCuboidShape(10, 11, 5, 11, 13, 11)
).reduce((v1, v2) -> VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR)).get();
private static final VoxelShape SHAPE_E = Stream.of(
Block.makeCuboidShape(5, 11, 5, 11, 13, 6),
Block.makeCuboidShape(4, 0, 4, 12, 1, 12),
Block.makeCuboidShape(5, 1, 5, 11, 2, 11),
Block.makeCuboidShape(6, 2, 6, 10, 10, 10),
Block.makeCuboidShape(4, 10, 5, 12, 11, 11),
Block.makeCuboidShape(11, 11, 5, 12, 12, 11),
Block.makeCuboidShape(4, 11, 5, 5, 14, 11),
Block.makeCuboidShape(5, 11, 10, 11, 13, 11)
).reduce((v1, v2) -> VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR)).get();
private static final VoxelShape SHAPE_S = Stream.of(
Block.makeCuboidShape(10, 11, 5, 11, 13, 11),
Block.makeCuboidShape(4, 0, 4, 12, 1, 12),
Block.makeCuboidShape(5, 1, 5, 11, 2, 11),
Block.makeCuboidShape(6, 2, 6, 10, 10, 10),
Block.makeCuboidShape(5, 10, 4, 11, 11, 12),
Block.makeCuboidShape(5, 11, 11, 11, 12, 12),
Block.makeCuboidShape(5, 11, 4, 11, 14, 5),
Block.makeCuboidShape(5, 11, 5, 6, 13, 11)
).reduce((v1, v2) -> VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR)).get();
private static final VoxelShape SHAPE_W = Stream.of(
Block.makeCuboidShape(5, 11, 10, 11, 13, 11),
Block.makeCuboidShape(4, 0, 4, 12, 1, 12),
Block.makeCuboidShape(5, 1, 5, 11, 2, 11),
Block.makeCuboidShape(6, 2, 6, 10, 10, 10),
Block.makeCuboidShape(4, 10, 5, 12, 11, 11),
Block.makeCuboidShape(4, 11, 5, 5, 12, 11),
Block.makeCuboidShape(11, 11, 5, 12, 14, 11),
Block.makeCuboidShape(5, 11, 5, 11, 13, 6)
).reduce((v1, v2) -> VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR)).get();
@Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos,
PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
if (!worldIn.isRemote()) {
if (!player.isCrouching()) {
MinecraftServer server = worldIn.getServer();
if (server != null) {
if (worldIn.getDimensionKey() == ModDimensions.TestDim) {
ServerWorld overWorld = server.getWorld(World.OVERWORLD);
if (overWorld != null) {
player.changeDimension(overWorld, new SimpleTeleporter(pos, false));
}
} else {
ServerWorld kjDim = server.getWorld(ModDimensions.TestDim);
if (kjDim != null) {
player.changeDimension(kjDim, new SimpleTeleporter(pos, true));
}
}
return ActionResultType.SUCCESS;
}
}
}
return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
switch (state.get(HORIZONTAL_FACING)) {
case NORTH:
return SHAPE_N;
case SOUTH:
return SHAPE_S;
case WEST:
return SHAPE_W;
case EAST:
return SHAPE_E;
default:
return SHAPE_N;
}
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(HORIZONTAL_FACING);
}
@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
return this.getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite());
}
}

View file

@ -1,16 +1,21 @@
package us.minecraftchest2.hdm_mod.item.custom;
import jdk.nashorn.internal.ir.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.ScoreTextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
public class SubtleKnife extends Item {
@ -23,19 +28,25 @@ public class SubtleKnife extends Item {
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
World world = context.getWorld();
// BlockPos pos =;
PlayerEntity player = context.getPlayer();
String message = "Item Used";
ITextComponent msg = new StringTextComponent(message);
assert player != null;
player.sendMessage(msg, player.getUniqueID());
// world.setBlockState(pos);
// if(world.isRemote) {
//
// }
return super.onItemUseFirst(stack, context);
if (player == null) return ActionResultType.PASS;
// Get the block being clicked
BlockPos blockPos = context.getPos();
Direction face = context.getFace(); // The face the player clicked
// Offset to the block face to place the block on the adjacent block (like right-clicking a wall places on it)
BlockPos placePos = blockPos.offset(face);
// Server-side logic only: place a block
if (!world.isRemote) {
world.setBlockState(placePos, Blocks.STONE.getDefaultState()); // Change to your portal block later
}
return ActionResultType.SUCCESS;
}
}

View file

@ -1,60 +1,74 @@
//package us.minecraftchest2.hdm_mod.world.dimension;
//
//import net.minecraft.block.material.Material;
//import net.minecraft.entity.Entity;
//import net.minecraft.fluid.Fluids;
//import net.minecraft.util.math.BlockPos;
//import net.minecraft.world.server.ServerWorld;
//import net.minecraftforge.common.util.ITeleporter;
//import us.minecraftchest2.hdm_mod.
//
//import java.util.function.Function;
//
//public class KJTeleporter implements ITeleporter {
// public static BlockPos thisPos = BlockPos.ZERO;
// public static boolean insideDimension = true;
//
// public KJTeleporter(BlockPos pos, boolean insideDim) {
// thisPos = pos;
// insideDimension = insideDim;
// }
//
// @Override
// public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destinationWorld,
// float yaw, Function<Boolean, Entity> repositionEntity) {
// entity = repositionEntity.apply(false);
// double y = 61;
//
// if (!insideDimension) {
// y = thisPos.getY();
// }
//
// BlockPos destinationPos = new BlockPos(thisPos.getX(), y, thisPos.getZ());
//
// int tries = 0;
// while ((destinationWorld.getBlockState(destinationPos).getMaterial() != Material.AIR) &&
// !destinationWorld.getBlockState(destinationPos).isReplaceable(Fluids.WATER) &&
// destinationWorld.getBlockState(destinationPos.up()).getMaterial() != Material.AIR &&
// !destinationWorld.getBlockState(destinationPos.up()).isReplaceable(Fluids.WATER) && tries < 25) {
// destinationPos = destinationPos.up(2);
// tries++;
// }
//
// entity.setPositionAndUpdate(destinationPos.getX(), destinationPos.getY(), destinationPos.getZ());
//
// if (insideDimension) {
// boolean doSetBlock = true;
// for (BlockPos checkPos : BlockPos.getAllInBoxMutable(destinationPos.down(10).west(10), destinationPos.up(10).east(10))) {
// if (destinationWorld.getBlockState(checkPos).getBlock() instanceof KaupenAltarBlock) {
// doSetBlock = false;
// break;
// }
// }
// if (doSetBlock) {
// destinationWorld.setBlockState(destinationPos, ModBlocks.KAUPEN_ALTAR.get().getDefaultState());
// }
// }
//
// return entity;
// }
//}
package us.minecraftchest2.hdm_mod.world.dimension;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.fluid.Fluids;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.ITeleporter;
import us.minecraftchest2.hdm_mod.block.ModBlocks;
import us.minecraftchest2.hdm_mod.block.custom.Window;
import java.util.function.Function;
public class SimpleTeleporter implements ITeleporter {
public static BlockPos thisPos = BlockPos.ZERO;
public static boolean insideDimension = true;
public SimpleTeleporter(BlockPos pos, boolean insideDim) {
thisPos = pos;
insideDimension = insideDim;
}
@Override
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destinationWorld,
float yaw, Function<Boolean, Entity> repositionEntity) {
entity = repositionEntity.apply(false);
double y = 61;
if (!insideDimension) {
y = thisPos.getY();
}
BlockPos destinationPos = new BlockPos(thisPos.getX(), y, thisPos.getZ());
int tries = 0;
while (
(
destinationWorld.getBlockState(destinationPos).getMaterial() != Material.AIR &&
!destinationWorld.getBlockState(destinationPos).isReplaceable(Fluids.WATER) &&
!destinationWorld.getBlockState(destinationPos).getMaterial().isReplaceable() ||
destinationWorld.getBlockState(destinationPos).getMaterial() == Material.LAVA ||
// destinationWorld.getBlockState(destinationPos).getBlock().isFire(destinationWorld, destinationPos, null) ||
destinationWorld.getBlockState(destinationPos.up()).getMaterial() != Material.AIR &&
!destinationWorld.getBlockState(destinationPos.up()).isReplaceable(Fluids.WATER) &&
!destinationWorld.getBlockState(destinationPos.up()).getMaterial().isReplaceable() ||
destinationWorld.getBlockState(destinationPos.up()).getMaterial() == Material.LAVA
// destinationWorld.getBlockState(destinationPos.up()).getBlock().isFire(destinationWorld, destinationPos.up(), null)
) && tries < 25
)
{
destinationPos = destinationPos.up(2);
tries++;
}
entity.setPositionAndUpdate(destinationPos.getX(), destinationPos.getY(), destinationPos.getZ());
if (insideDimension) {
boolean doSetBlock = true;
for (BlockPos checkPos : BlockPos.getAllInBoxMutable(destinationPos.down(10).west(10), destinationPos.up(10).east(10))) {
if (destinationWorld.getBlockState(checkPos).getBlock() instanceof Window) {
doSetBlock = false;
break;
}
}
if (doSetBlock) {
destinationWorld.setBlockState(destinationPos, ModBlocks.PORTAL_BLOCK.get().getDefaultState());
}
}
return entity;
}
}