mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 11:53:29 +01:00
added pipe wrench
This commit is contained in:
parent
44595ab0a8
commit
46ef0ef0a9
8 changed files with 143 additions and 30 deletions
|
@ -83,20 +83,13 @@ sourceSets.main.resources {
|
|||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url = "https://dvs1.progwml6.com/files/maven"
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
embed
|
||||
compile.extendsFrom(embed)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft 'net.minecraftforge:forge:1.15.2-31.1.19'
|
||||
embed "org.jgrapht:jgrapht-core:1.4.0"
|
||||
|
||||
compileOnly fg.deobf("mezz.jei:jei-1.15.2:6.0.0.2:api")
|
||||
runtimeOnly fg.deobf("mezz.jei:jei-1.15.2:6.0.0.2")
|
||||
|
@ -115,7 +108,6 @@ jar {
|
|||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
])
|
||||
}
|
||||
from configurations.embed.collect { it.isDirectory() ? it : zipTree(it) }
|
||||
}
|
||||
|
||||
task deobfJar(type: Jar) {
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package de.ellpeck.prettypipes;
|
||||
|
||||
import de.ellpeck.prettypipes.blocks.PipeBlock;
|
||||
import de.ellpeck.prettypipes.items.WrenchItem;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.RenderTypeLookup;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
@ -18,6 +20,14 @@ import net.minecraftforge.registries.ForgeRegistries;
|
|||
@Mod.EventBusSubscriber(bus = Bus.MOD)
|
||||
public final class Registry {
|
||||
|
||||
public static final ItemGroup GROUP = new ItemGroup(PrettyPipes.ID) {
|
||||
@Override
|
||||
public ItemStack createIcon() {
|
||||
return new ItemStack(wrench);
|
||||
}
|
||||
};
|
||||
|
||||
public static Item wrench;
|
||||
public static Block pipe;
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -29,9 +39,13 @@ public final class Registry {
|
|||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event) {
|
||||
event.getRegistry().registerAll(
|
||||
wrench = new WrenchItem().setRegistryName("wrench")
|
||||
);
|
||||
|
||||
ForgeRegistries.BLOCKS.getValues().stream()
|
||||
.filter(b -> b.getRegistryName().getNamespace().equals(PrettyPipes.ID))
|
||||
.forEach(b -> event.getRegistry().register(new BlockItem(b, new Item.Properties().group(ItemGroup.MISC)).setRegistryName(b.getRegistryName())));
|
||||
.forEach(b -> event.getRegistry().register(new BlockItem(b, new Item.Properties().group(GROUP)).setRegistryName(b.getRegistryName())));
|
||||
}
|
||||
|
||||
public static void setup(FMLCommonSetupEvent event) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.state.EnumProperty;
|
|||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.datafix.fixes.BlockEntityKeepPacked;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
|
@ -29,7 +30,7 @@ public class PipeBlock extends Block {
|
|||
public static final Map<Direction, EnumProperty<ConnectionType>> DIRECTIONS = new HashMap<>();
|
||||
private static final Map<BlockState, VoxelShape> SHAPE_CACHE = new HashMap<>();
|
||||
private static final VoxelShape CENTER_SHAPE = makeCuboidShape(5, 5, 5, 11, 11, 11);
|
||||
private static final Map<Direction, VoxelShape> DIR_SHAPES = ImmutableMap.<Direction, VoxelShape>builder()
|
||||
public static final Map<Direction, VoxelShape> DIR_SHAPES = ImmutableMap.<Direction, VoxelShape>builder()
|
||||
.put(Direction.UP, makeCuboidShape(5, 10, 5, 11, 16, 11))
|
||||
.put(Direction.DOWN, makeCuboidShape(5, 0, 5, 11, 6, 11))
|
||||
.put(Direction.NORTH, makeCuboidShape(5, 5, 0, 11, 11, 6))
|
||||
|
@ -59,7 +60,7 @@ public class PipeBlock extends Block {
|
|||
|
||||
@Override
|
||||
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
|
||||
BlockState newState = this.createState(worldIn, pos);
|
||||
BlockState newState = this.createState(worldIn, pos, state);
|
||||
if (newState != state)
|
||||
worldIn.setBlockState(pos, newState);
|
||||
}
|
||||
|
@ -67,24 +68,7 @@ public class PipeBlock extends Block {
|
|||
@Nullable
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
return this.createState(context.getWorld(), context.getPos());
|
||||
}
|
||||
|
||||
private BlockState createState(World world, BlockPos pos) {
|
||||
BlockState state = this.getDefaultState();
|
||||
for (Map.Entry<Direction, EnumProperty<ConnectionType>> entry : DIRECTIONS.entrySet()) {
|
||||
BlockPos neighborPos = pos.offset(entry.getKey());
|
||||
boolean canConnect = this.canConnect(world, neighborPos);
|
||||
state = state.with(entry.getValue(), canConnect ? ConnectionType.CONNECTED : ConnectionType.DISCONNECTED);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
private boolean canConnect(World world, BlockPos offset) {
|
||||
if (!world.isBlockLoaded(offset))
|
||||
return false;
|
||||
BlockState state = world.getBlockState(offset);
|
||||
return state.getBlock() == this;
|
||||
return this.createState(context.getWorld(), context.getPos(), this.getDefaultState());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,9 +91,33 @@ public class PipeBlock extends Block {
|
|||
return shape;
|
||||
}
|
||||
|
||||
private BlockState createState(World world, BlockPos pos, BlockState current) {
|
||||
BlockState state = this.getDefaultState();
|
||||
for (Map.Entry<Direction, EnumProperty<ConnectionType>> entry : DIRECTIONS.entrySet()) {
|
||||
ConnectionType type = getConnectionType(world, pos, entry.getKey());
|
||||
if (type == ConnectionType.CONNECTED && current.get(entry.getValue()) == ConnectionType.BLOCKED)
|
||||
type = ConnectionType.BLOCKED;
|
||||
state = state.with(entry.getValue(), type);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
public static ConnectionType getConnectionType(World world, BlockPos pos, Direction direction) {
|
||||
BlockPos offset = pos.offset(direction);
|
||||
if (!world.isBlockLoaded(offset))
|
||||
return ConnectionType.DISCONNECTED;
|
||||
BlockState state = world.getBlockState(offset);
|
||||
if (!(state.getBlock() instanceof PipeBlock))
|
||||
return ConnectionType.DISCONNECTED;
|
||||
if (state.get(DIRECTIONS.get(direction.getOpposite())) == ConnectionType.BLOCKED)
|
||||
return ConnectionType.BLOCKED;
|
||||
return ConnectionType.CONNECTED;
|
||||
}
|
||||
|
||||
public enum ConnectionType implements IStringSerializable {
|
||||
CONNECTED,
|
||||
DISCONNECTED;
|
||||
DISCONNECTED,
|
||||
BLOCKED;
|
||||
|
||||
private final String name;
|
||||
|
||||
|
|
69
src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java
Normal file
69
src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
package de.ellpeck.prettypipes.items;
|
||||
|
||||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.blocks.PipeBlock;
|
||||
import de.ellpeck.prettypipes.blocks.PipeBlock.ConnectionType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.state.EnumProperty;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class WrenchItem extends Item {
|
||||
public WrenchItem() {
|
||||
super(new Item.Properties().maxStackSize(1).group(Registry.GROUP));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onItemUse(ItemUseContext context) {
|
||||
World world = context.getWorld();
|
||||
BlockPos pos = context.getPos();
|
||||
BlockState state = world.getBlockState(pos);
|
||||
if (!(state.getBlock() instanceof PipeBlock))
|
||||
return ActionResultType.PASS;
|
||||
|
||||
if (context.getPlayer().isShiftKeyDown()) {
|
||||
if (!world.isRemote) {
|
||||
Block.spawnDrops(state, world, pos, world.getTileEntity(pos), null, ItemStack.EMPTY);
|
||||
world.playSound(null, pos, SoundEvents.ENTITY_ITEM_FRAME_REMOVE_ITEM, SoundCategory.PLAYERS, 1, 1);
|
||||
world.removeBlock(pos, false);
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
// Blocking
|
||||
for (Map.Entry<Direction, VoxelShape> entry : PipeBlock.DIR_SHAPES.entrySet()) {
|
||||
AxisAlignedBB box = entry.getValue().getBoundingBox().offset(pos).grow(0.001F);
|
||||
if (!box.contains(context.getHitVec()))
|
||||
continue;
|
||||
EnumProperty<ConnectionType> prop = PipeBlock.DIRECTIONS.get(entry.getKey());
|
||||
ConnectionType curr = state.get(prop);
|
||||
if (curr == ConnectionType.DISCONNECTED)
|
||||
continue;
|
||||
|
||||
if (!world.isRemote) {
|
||||
ConnectionType newType = curr == ConnectionType.BLOCKED ? ConnectionType.CONNECTED : ConnectionType.BLOCKED;
|
||||
BlockState newState = state.with(prop, newType);
|
||||
world.setBlockState(pos, newState);
|
||||
|
||||
BlockPos otherPos = pos.offset(entry.getKey());
|
||||
world.setBlockState(otherPos, world.getBlockState(otherPos).with(PipeBlock.DIRECTIONS.get(entry.getKey().getOpposite()), newType));
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
}
|
5
src/main/resources/assets/prettypipes/lang/en_us.json
Normal file
5
src/main/resources/assets/prettypipes/lang/en_us.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"item.prettypipes.wrench": "Pipe Wrench",
|
||||
"block.prettypipes.pipe": "Pipe",
|
||||
"itemGroup.prettypipes": "Pretty Pipes"
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "item/handheld",
|
||||
"textures": {
|
||||
"layer0": "prettypipes:item/wrench"
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/prettypipes/textures/item/wrench.png
Normal file
BIN
src/main/resources/assets/prettypipes/textures/item/wrench.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 284 B |
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "prettypipes:pipe"
|
||||
}
|
||||
],
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:survives_explosion"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue