mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 11:53:29 +01:00
finished the pipe frame
This commit is contained in:
parent
cfee160573
commit
3e10688a96
10 changed files with 162 additions and 25 deletions
|
@ -70,6 +70,7 @@ public final class Registry {
|
|||
public static Capability<PipeNetwork> pipeNetworkCapability;
|
||||
|
||||
public static Item wrenchItem;
|
||||
public static Item pipeFrameItem;
|
||||
|
||||
public static Block pipeBlock;
|
||||
public static TileEntityType<PipeTileEntity> pipeTileEntity;
|
||||
|
@ -95,7 +96,7 @@ public final class Registry {
|
|||
registry.registerAll(
|
||||
wrenchItem = new WrenchItem().setRegistryName("wrench"),
|
||||
new Item(new Item.Properties().group(GROUP)).setRegistryName("blank_module"),
|
||||
new PipeFrameItem().setRegistryName("pipe_frame")
|
||||
pipeFrameItem = new PipeFrameItem().setRegistryName("pipe_frame")
|
||||
);
|
||||
registry.registerAll(createTieredModule("extraction_module", ExtractionModuleItem::new));
|
||||
registry.registerAll(createTieredModule("filter_module", FilterModuleItem::new));
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
package de.ellpeck.prettypipes;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.*;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class Utility {
|
||||
|
||||
public static <T extends TileEntity> T getTileEntity(Class<T> type, World world, BlockPos pos) {
|
||||
|
@ -28,4 +33,14 @@ public final class Utility {
|
|||
BlockPos diff = pos.subtract(other);
|
||||
return Direction.getFacingFromVector(diff.getX(), diff.getY(), diff.getZ());
|
||||
}
|
||||
|
||||
public static void addTooltip(String name, List<ITextComponent> tooltip) {
|
||||
if (Screen.hasShiftDown()) {
|
||||
String[] content = I18n.format("info." + PrettyPipes.ID + "." + name).split("\n");
|
||||
for (String s : content)
|
||||
tooltip.add(new StringTextComponent(s).setStyle(new Style().setColor(TextFormatting.GRAY)));
|
||||
} else {
|
||||
tooltip.add(new TranslationTextComponent("info." + PrettyPipes.ID + ".shift").setStyle(new Style().setColor(TextFormatting.DARK_GRAY)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,33 @@
|
|||
package de.ellpeck.prettypipes.entities;
|
||||
|
||||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.network.NetworkLocation;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlock;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.item.ItemFrameEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.FilledMapItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.network.IPacket;
|
||||
import net.minecraft.network.datasync.DataParameter;
|
||||
import net.minecraft.network.datasync.DataSerializers;
|
||||
import net.minecraft.network.datasync.EntityDataManager;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.GameRules;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.MapData;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class PipeFrameEntity extends ItemFrameEntity {
|
||||
|
@ -34,7 +47,7 @@ public class PipeFrameEntity extends ItemFrameEntity {
|
|||
@Override
|
||||
protected void registerData() {
|
||||
super.registerData();
|
||||
this.dataManager.register(AMOUNT, 0);
|
||||
this.dataManager.register(AMOUNT, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,20 +58,101 @@ public class PipeFrameEntity extends ItemFrameEntity {
|
|||
if (this.ticksExisted % 40 != 0)
|
||||
return;
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
BlockPos hangingPos = this.getHangingPosition().offset(this.getHorizontalFacing().getOpposite());
|
||||
BlockPos node = network.getNodeFromPipe(hangingPos);
|
||||
if (node == null)
|
||||
return;
|
||||
ItemStack stack = this.getDisplayedItem();
|
||||
List<NetworkLocation> items = network.getOrderedNetworkItems(node);
|
||||
int amount = items.stream().mapToInt(i -> i.getItemAmount(stack)).sum();
|
||||
this.dataManager.set(AMOUNT, amount);
|
||||
BlockPos attached = getAttachedPipe(this.world, this.hangingPosition, this.facingDirection);
|
||||
if (attached != null) {
|
||||
BlockPos node = network.getNodeFromPipe(attached);
|
||||
if (node != null) {
|
||||
ItemStack stack = this.getDisplayedItem();
|
||||
if (!stack.isEmpty()) {
|
||||
List<NetworkLocation> items = network.getOrderedNetworkItems(node);
|
||||
int amount = items.stream().mapToInt(i -> i.getItemAmount(stack)).sum();
|
||||
this.dataManager.set(AMOUNT, amount);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.dataManager.set(AMOUNT, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onValidSurface() {
|
||||
return super.onValidSurface() && canPlace(this.world, this.hangingPosition, this.facingDirection);
|
||||
}
|
||||
|
||||
private static BlockPos getAttachedPipe(World world, BlockPos pos, Direction direction) {
|
||||
for (int i = 1; i <= 2; i++) {
|
||||
BlockPos offset = pos.offset(direction.getOpposite(), i);
|
||||
BlockState state = world.getBlockState(offset);
|
||||
if (state.getBlock() instanceof PipeBlock)
|
||||
return offset;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean canPlace(World world, BlockPos pos, Direction direction) {
|
||||
return getAttachedPipe(world, pos, direction) != null;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return this.dataManager.get(AMOUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attackEntityFrom(DamageSource source, float amount) {
|
||||
if (this.isInvulnerableTo(source)) {
|
||||
return false;
|
||||
} else if (!source.isExplosion() && !this.getDisplayedItem().isEmpty()) {
|
||||
if (!this.world.isRemote) {
|
||||
this.dropItemOrSelf(source.getTrueSource(), false);
|
||||
this.playSound(SoundEvents.ENTITY_ITEM_FRAME_REMOVE_ITEM, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return super.attackEntityFrom(source, amount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBroken(@Nullable Entity brokenEntity) {
|
||||
this.playSound(SoundEvents.ENTITY_ITEM_FRAME_BREAK, 1.0F, 1.0F);
|
||||
this.dropItemOrSelf(brokenEntity, true);
|
||||
}
|
||||
|
||||
private void dropItemOrSelf(@Nullable Entity entityIn, boolean b) {
|
||||
if (!this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) {
|
||||
if (entityIn == null)
|
||||
this.getDisplayedItem().setItemFrame(null);
|
||||
} else {
|
||||
ItemStack itemstack = this.getDisplayedItem();
|
||||
this.setDisplayedItem(ItemStack.EMPTY);
|
||||
if (entityIn instanceof PlayerEntity) {
|
||||
PlayerEntity playerentity = (PlayerEntity) entityIn;
|
||||
if (playerentity.abilities.isCreativeMode) {
|
||||
itemstack.setItemFrame(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (b)
|
||||
this.entityDropItem(Registry.pipeFrameItem);
|
||||
|
||||
if (!itemstack.isEmpty()) {
|
||||
itemstack = itemstack.copy();
|
||||
itemstack.setItemFrame(null);
|
||||
this.entityDropItem(itemstack);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processInitialInteract(PlayerEntity player, Hand hand) {
|
||||
if (this.getDisplayedItem().isEmpty())
|
||||
return super.processInitialInteract(player, hand);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPacket<?> createSpawnPacket() {
|
||||
return NetworkHooks.getEntitySpawningPacket(this);
|
||||
|
|
|
@ -21,8 +21,6 @@ public class PipeFrameRenderer extends ItemFrameRenderer {
|
|||
@Override
|
||||
public void render(ItemFrameEntity entityIn, float entityYaw, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn) {
|
||||
super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn);
|
||||
if (entityIn.getDisplayedItem().isEmpty())
|
||||
return;
|
||||
matrixStackIn.push();
|
||||
Direction direction = entityIn.getHorizontalFacing();
|
||||
Vec3d vec3d = this.getRenderOffset(entityIn, partialTicks);
|
||||
|
@ -33,10 +31,10 @@ public class PipeFrameRenderer extends ItemFrameRenderer {
|
|||
|
||||
FontRenderer font = this.getFontRendererFromRenderManager();
|
||||
int amount = ((PipeFrameEntity) entityIn).getAmount();
|
||||
String ammountStrg = String.valueOf(amount);
|
||||
String ammountStrg = amount < 0 ? "?" : String.valueOf(amount);
|
||||
float x = 0.5F - font.getStringWidth(ammountStrg) / 2F;
|
||||
Matrix4f matrix4f = matrixStackIn.getLast().getPositionMatrix();
|
||||
matrixStackIn.translate(0, -0.13F, 0);
|
||||
matrixStackIn.translate(0, 0.285F, 0);
|
||||
matrixStackIn.scale(-0.02F, -0.02F, 0.02F);
|
||||
font.renderString(ammountStrg, x, 0, 0xFFFFFF, true, matrix4f, bufferIn, false, 0, packedLightIn);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.ellpeck.prettypipes.items;
|
|||
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.pipe.modules.containers.AbstractPipeContainer;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
@ -33,13 +34,7 @@ public abstract class ModuleItem extends Item implements IModule {
|
|||
@OnlyIn(Dist.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
if (Screen.hasShiftDown()) {
|
||||
String[] content = I18n.format("info." + PrettyPipes.ID + "." + this.name).split("\n");
|
||||
for (String s : content)
|
||||
tooltip.add(new StringTextComponent(s).setStyle(new Style().setColor(TextFormatting.GRAY)));
|
||||
} else {
|
||||
tooltip.add(new TranslationTextComponent("info." + PrettyPipes.ID + ".shift").setStyle(new Style().setColor(TextFormatting.DARK_GRAY)));
|
||||
}
|
||||
Utility.addTooltip(this.name, tooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package de.ellpeck.prettypipes.items;
|
||||
|
||||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.entities.PipeFrameEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.item.HangingEntity;
|
||||
import net.minecraft.entity.item.ItemFrameEntity;
|
||||
|
@ -16,8 +18,12 @@ import net.minecraft.nbt.CompoundNBT;
|
|||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class PipeFrameItem extends Item {
|
||||
public PipeFrameItem() {
|
||||
super(new Properties().group(Registry.GROUP));
|
||||
|
@ -57,9 +63,12 @@ public class PipeFrameItem extends Item {
|
|||
}
|
||||
|
||||
protected boolean canPlace(PlayerEntity playerIn, Direction directionIn, ItemStack itemStackIn, BlockPos posIn) {
|
||||
BlockState state = playerIn.world.getBlockState(posIn.offset(directionIn.getOpposite()));
|
||||
if (!(state.getBlock() instanceof PipeBlock))
|
||||
return false;
|
||||
return !directionIn.getAxis().isVertical() && playerIn.canPlayerEdit(posIn, directionIn, itemStackIn);
|
||||
return !directionIn.getAxis().isVertical() && playerIn.canPlayerEdit(posIn, directionIn, itemStackIn) && PipeFrameEntity.canPlace(playerIn.world, posIn, directionIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
Utility.addTooltip(this.getRegistryName().getPath(), tooltip);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
"item.prettypipes.wrench": "Pipe Wrench",
|
||||
"item.prettypipes.blank_module": "Blank Module",
|
||||
"item.prettypipes.pipe_frame": "Pipe Frame",
|
||||
"info.prettypipes.pipe_frame": "Attach to a pipe or pipe-adjacent block\nShows amount of an item in the pipe's network",
|
||||
"item.prettypipes.low_extraction_module": "Low Extraction Module",
|
||||
"item.prettypipes.medium_extraction_module": "Medium Extraction Module",
|
||||
"item.prettypipes.high_extraction_module": "High Extraction Module",
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "prettypipes:item/pipe_frame"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 365 B |
17
src/main/resources/data/prettypipes/recipes/pipe_frame.json
Normal file
17
src/main/resources/data/prettypipes/recipes/pipe_frame.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"type": "minecraft:crafting_shapeless",
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:item_frame"
|
||||
},
|
||||
{
|
||||
"item": "prettypipes:pipe"
|
||||
},
|
||||
{
|
||||
"item": "minecraft:redstone"
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"item": "prettypipes:pipe_frame"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue