mirror of
https://github.com/dragonruler1000/hdm-mod.git
synced 2025-06-29 16:39:32 -05:00
Added a window block and working on portal stuff.
Signed-off-by: dragonruler1000 <github@me.minecraftchest2.us>
This commit is contained in:
parent
c7269ce21c
commit
a195450501
5 changed files with 230 additions and 76 deletions
|
@ -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.
|
// 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}"
|
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
|
// Example mod dependency using a mod jar from ./libs with a flat dir repository
|
||||||
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
|
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.util.function.ToIntFunction;
|
||||||
|
|
||||||
public class ModBlocks {
|
public class ModBlocks {
|
||||||
public static ToIntFunction<BlockState> dustLightLevel = BlockState -> 10; // Dust Light Level
|
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);
|
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)
|
() -> new Block(AbstractBlock.Properties.create(Material.ROCK).doesNotBlockMovement().harvestLevel(0)
|
||||||
.hardnessAndResistance(500f, 100f).setLightLevel(dustLightLevel)));
|
.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) {
|
private static <T extends Block>RegistryObject<T> registerBlock(String name, Supplier<T> block) {
|
||||||
RegistryObject<T> toReturn = BLOCKS.register(name, block);
|
RegistryObject<T> toReturn = BLOCKS.register(name, block);
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,16 +1,21 @@
|
||||||
package us.minecraftchest2.hdm_mod.item.custom;
|
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.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.ItemUseContext;
|
import net.minecraft.item.ItemUseContext;
|
||||||
import net.minecraft.util.ActionResultType;
|
import net.minecraft.util.ActionResultType;
|
||||||
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.math.BlockPos;
|
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.ITextComponent;
|
||||||
import net.minecraft.util.text.ScoreTextComponent;
|
import net.minecraft.util.text.ScoreTextComponent;
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
import net.minecraft.util.text.StringTextComponent;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.client.MinecraftForgeClient;
|
||||||
|
|
||||||
|
|
||||||
public class SubtleKnife extends Item {
|
public class SubtleKnife extends Item {
|
||||||
|
@ -23,19 +28,25 @@ public class SubtleKnife extends Item {
|
||||||
@Override
|
@Override
|
||||||
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
|
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
|
||||||
World world = context.getWorld();
|
World world = context.getWorld();
|
||||||
// BlockPos pos =;
|
|
||||||
PlayerEntity player = context.getPlayer();
|
PlayerEntity player = context.getPlayer();
|
||||||
|
|
||||||
String message = "Item Used";
|
if (player == null) return ActionResultType.PASS;
|
||||||
ITextComponent msg = new StringTextComponent(message);
|
|
||||||
assert player != null;
|
// Get the block being clicked
|
||||||
player.sendMessage(msg, player.getUniqueID());
|
BlockPos blockPos = context.getPos();
|
||||||
// world.setBlockState(pos);
|
Direction face = context.getFace(); // The face the player clicked
|
||||||
// if(world.isRemote) {
|
|
||||||
//
|
// 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);
|
||||||
return super.onItemUseFirst(stack, context);
|
|
||||||
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,60 +1,74 @@
|
||||||
//package us.minecraftchest2.hdm_mod.world.dimension;
|
package us.minecraftchest2.hdm_mod.world.dimension;
|
||||||
//
|
|
||||||
//import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
//import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
//import net.minecraft.fluid.Fluids;
|
import net.minecraft.fluid.Fluids;
|
||||||
//import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
//import net.minecraft.world.server.ServerWorld;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
//import net.minecraftforge.common.util.ITeleporter;
|
import net.minecraftforge.common.util.ITeleporter;
|
||||||
//import us.minecraftchest2.hdm_mod.
|
import us.minecraftchest2.hdm_mod.block.ModBlocks;
|
||||||
//
|
import us.minecraftchest2.hdm_mod.block.custom.Window;
|
||||||
//import java.util.function.Function;
|
|
||||||
//
|
|
||||||
//public class KJTeleporter implements ITeleporter {
|
import java.util.function.Function;
|
||||||
// public static BlockPos thisPos = BlockPos.ZERO;
|
|
||||||
// public static boolean insideDimension = true;
|
public class SimpleTeleporter implements ITeleporter {
|
||||||
//
|
public static BlockPos thisPos = BlockPos.ZERO;
|
||||||
// public KJTeleporter(BlockPos pos, boolean insideDim) {
|
public static boolean insideDimension = true;
|
||||||
// thisPos = pos;
|
|
||||||
// insideDimension = insideDim;
|
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) {
|
@Override
|
||||||
// entity = repositionEntity.apply(false);
|
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destinationWorld,
|
||||||
// double y = 61;
|
float yaw, Function<Boolean, Entity> repositionEntity) {
|
||||||
//
|
entity = repositionEntity.apply(false);
|
||||||
// if (!insideDimension) {
|
double y = 61;
|
||||||
// y = thisPos.getY();
|
|
||||||
// }
|
if (!insideDimension) {
|
||||||
//
|
y = thisPos.getY();
|
||||||
// BlockPos destinationPos = new BlockPos(thisPos.getX(), y, thisPos.getZ());
|
}
|
||||||
//
|
|
||||||
// int tries = 0;
|
BlockPos destinationPos = new BlockPos(thisPos.getX(), y, thisPos.getZ());
|
||||||
// while ((destinationWorld.getBlockState(destinationPos).getMaterial() != Material.AIR) &&
|
|
||||||
// !destinationWorld.getBlockState(destinationPos).isReplaceable(Fluids.WATER) &&
|
|
||||||
// destinationWorld.getBlockState(destinationPos.up()).getMaterial() != Material.AIR &&
|
int tries = 0;
|
||||||
// !destinationWorld.getBlockState(destinationPos.up()).isReplaceable(Fluids.WATER) && tries < 25) {
|
while (
|
||||||
// destinationPos = destinationPos.up(2);
|
(
|
||||||
// tries++;
|
destinationWorld.getBlockState(destinationPos).getMaterial() != Material.AIR &&
|
||||||
// }
|
!destinationWorld.getBlockState(destinationPos).isReplaceable(Fluids.WATER) &&
|
||||||
//
|
!destinationWorld.getBlockState(destinationPos).getMaterial().isReplaceable() ||
|
||||||
// entity.setPositionAndUpdate(destinationPos.getX(), destinationPos.getY(), destinationPos.getZ());
|
destinationWorld.getBlockState(destinationPos).getMaterial() == Material.LAVA ||
|
||||||
//
|
// destinationWorld.getBlockState(destinationPos).getBlock().isFire(destinationWorld, destinationPos, null) ||
|
||||||
// if (insideDimension) {
|
destinationWorld.getBlockState(destinationPos.up()).getMaterial() != Material.AIR &&
|
||||||
// boolean doSetBlock = true;
|
!destinationWorld.getBlockState(destinationPos.up()).isReplaceable(Fluids.WATER) &&
|
||||||
// for (BlockPos checkPos : BlockPos.getAllInBoxMutable(destinationPos.down(10).west(10), destinationPos.up(10).east(10))) {
|
!destinationWorld.getBlockState(destinationPos.up()).getMaterial().isReplaceable() ||
|
||||||
// if (destinationWorld.getBlockState(checkPos).getBlock() instanceof KaupenAltarBlock) {
|
destinationWorld.getBlockState(destinationPos.up()).getMaterial() == Material.LAVA
|
||||||
// doSetBlock = false;
|
// destinationWorld.getBlockState(destinationPos.up()).getBlock().isFire(destinationWorld, destinationPos.up(), null)
|
||||||
// break;
|
) && tries < 25
|
||||||
// }
|
)
|
||||||
// }
|
{
|
||||||
// if (doSetBlock) {
|
destinationPos = destinationPos.up(2);
|
||||||
// destinationWorld.setBlockState(destinationPos, ModBlocks.KAUPEN_ALTAR.get().getDefaultState());
|
tries++;
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
//
|
entity.setPositionAndUpdate(destinationPos.getX(), destinationPos.getY(), destinationPos.getZ());
|
||||||
// return entity;
|
|
||||||
// }
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue