-
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
21 changed files
with
516 additions
and
4 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
80 changes: 80 additions & 0 deletions
80
src/main/java/com/pitheguy/magicmod/blocks/MagicPress.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,80 @@ | ||
package com.pitheguy.magicmod.blocks; | ||
|
||
import com.pitheguy.magicmod.init.ModTileEntityTypes; | ||
import com.pitheguy.magicmod.tileentity.MagicPressTileEntity; | ||
import com.pitheguy.magicmod.util.ModItemHandler; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.SoundType; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.item.ItemEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.player.ServerPlayerEntity; | ||
import net.minecraft.inventory.container.INamedContainerProvider; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.tileentity.TileEntity; | ||
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.world.IBlockReader; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.common.ToolType; | ||
import net.minecraftforge.fml.network.NetworkHooks; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class MagicPress extends Block { | ||
|
||
public MagicPress() { | ||
super(Properties.create(Material.IRON) | ||
.hardnessAndResistance(6.5f, 8.0f) | ||
.sound(SoundType.METAL) | ||
.harvestLevel(4) | ||
.harvestTool(ToolType.PICKAXE) | ||
); | ||
} | ||
|
||
@Override | ||
public boolean hasTileEntity(BlockState state) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public TileEntity createTileEntity(BlockState state, IBlockReader world) { | ||
return ModTileEntityTypes.MAGIC_PRESS.get().create(); | ||
} | ||
|
||
@Override | ||
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { | ||
super.onBlockPlacedBy(worldIn, pos, state, placer, stack); | ||
} | ||
|
||
@Override | ||
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { | ||
if (worldIn != null && !worldIn.isRemote()) { | ||
TileEntity tile = worldIn.getTileEntity(pos); | ||
if(tile instanceof MagicPressTileEntity) { | ||
NetworkHooks.openGui((ServerPlayerEntity) player,(INamedContainerProvider) tile,pos); | ||
return ActionResultType.SUCCESS; | ||
} | ||
} | ||
return ActionResultType.SUCCESS; | ||
} | ||
|
||
@Override | ||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { | ||
TileEntity tile = worldIn.getTileEntity(pos); | ||
if(tile instanceof MagicPressTileEntity) { | ||
MagicPressTileEntity infuser = (MagicPressTileEntity) tile; | ||
((ModItemHandler)infuser.getInventory()).toNonNullList().forEach(item -> { | ||
ItemEntity itemEntity = new ItemEntity(worldIn, pos.getX(), pos.getY(), pos.getZ(), item); | ||
worldIn.addEntity(itemEntity); | ||
}); | ||
} | ||
if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) { | ||
worldIn.removeTileEntity(pos); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/pitheguy/magicmod/client/gui/MagicPressScreen.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,42 @@ | ||
package com.pitheguy.magicmod.client.gui; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import com.pitheguy.magicmod.container.MagicPressContainer; | ||
import net.minecraft.client.gui.screen.inventory.ContainerScreen; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.util.text.ITextComponent; | ||
|
||
public class MagicPressScreen extends ContainerScreen<MagicPressContainer> { | ||
private static final ResourceLocation TEXTURE = new ResourceLocation("magicmod", "textures/gui/magic_press.png"); | ||
public MagicPressScreen(MagicPressContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) { | ||
super(screenContainer, inv, titleIn); | ||
|
||
this.guiLeft = 0; | ||
this.guiTop = 0; | ||
this.xSize = 176; | ||
this.ySize = 162; | ||
} | ||
|
||
@Override | ||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { | ||
RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f); | ||
this.minecraft.getTextureManager().bindTexture(TEXTURE); | ||
this.blit(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); | ||
this.blit(this.guiLeft + 49, this.guiTop + 53, 0, 165, this.container.getFuelScaled(), 16); | ||
} | ||
|
||
@Override | ||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { | ||
super.drawGuiContainerForegroundLayer(mouseX, mouseY); | ||
this.font.drawString(this.title.getFormattedText(), 8, 8, 0x404040); | ||
this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8, 70, 0x404040); | ||
} | ||
|
||
@Override | ||
public void render(int mouseX, int mouseY, float partialTicks) { | ||
this.renderBackground(); | ||
super.render(mouseX, mouseY, partialTicks); | ||
this.renderHoveredToolTip(mouseX, mouseY); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/pitheguy/magicmod/container/MagicInfuserContainer.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
115 changes: 115 additions & 0 deletions
115
src/main/java/com/pitheguy/magicmod/container/MagicPressContainer.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,115 @@ | ||
package com.pitheguy.magicmod.container; | ||
|
||
import com.pitheguy.magicmod.container.itemhandlers.MultiItemSlotItemHandler; | ||
import com.pitheguy.magicmod.container.itemhandlers.SingleItemSlotItemHandler; | ||
import com.pitheguy.magicmod.init.ModContainerTypes; | ||
import com.pitheguy.magicmod.tileentity.MagicPressTileEntity; | ||
import com.pitheguy.magicmod.util.FunctionalIntReferenceHolder; | ||
import com.pitheguy.magicmod.util.RegistryHandler; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.inventory.container.Container; | ||
import net.minecraft.inventory.container.Slot; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.network.PacketBuffer; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.util.IWorldPosCallable; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
import static com.pitheguy.magicmod.util.RegistryHandler.*; | ||
|
||
public class MagicPressContainer extends Container { | ||
|
||
public MagicPressTileEntity tileEntity; | ||
private final IWorldPosCallable canInteractWithCallable; | ||
public FunctionalIntReferenceHolder fuel; | ||
|
||
//Server constructor | ||
public MagicPressContainer(final int windowID, final PlayerInventory playerInv, final MagicPressTileEntity tile) { | ||
super(ModContainerTypes.MAGIC_PRESS.get(), windowID); | ||
this.canInteractWithCallable = IWorldPosCallable.of(tile.getWorld(), tile.getPos()); | ||
this.tileEntity = tile; | ||
final int slotSizePlus2 = 18; | ||
final int startX = 8; | ||
//Hotbar | ||
int hotbarY = 139; | ||
for (int col = 0; col < 9; col++) { | ||
this.addSlot(new Slot(playerInv, col, (startX + (col * slotSizePlus2)), hotbarY)); | ||
} | ||
//Main Player Inventory | ||
int startY = 81; | ||
for (int row = 0; row < 3; row++) { | ||
for (int col = 0; col < 9; col++) { | ||
this.addSlot(new Slot(playerInv, 9+(row*9)+col, startX + (col * slotSizePlus2), startY + (row * slotSizePlus2))); | ||
} | ||
} | ||
//Magic Press Inventory | ||
this.addSlot(new MultiItemSlotItemHandler(tile.getInventory(), 0, 27, 19, Arrays.asList(MAGIC_HELMET.get(),MAGIC_CHESTPLATE.get(),MAGIC_LEGGINGS.get(),MAGIC_BOOTS.get(),MAGIC_PICKAXE.get(),MAGIC_AXE.get(),MAGIC_SHOVEL.get(),MAGIC_SWORD.get(),MAGIC_HOE.get()))); | ||
this.addSlot(new SingleItemSlotItemHandler(tile.getInventory(), 1, 76, 19, MAGIC_PLATE.get())); | ||
this.addSlot(new MultiItemSlotItemHandler(tile.getInventory(), 2, 134,19, Arrays.asList(REINFORCED_MAGIC_HELMET.get(), REINFORCED_MAGIC_CHESTPLATE.get(), REINFORCED_MAGIC_LEGGINGS.get(), REINFORCED_MAGIC_BOOTS.get(), REINFORCED_MAGIC_PICKAXE.get(), REINFORCED_MAGIC_AXE.get(), REINFORCED_MAGIC_SHOVEL.get(), REINFORCED_MAGIC_SWORD.get(), REINFORCED_MAGIC_HOE.get()))); | ||
this.addSlot(new MultiItemSlotItemHandler(tile.getInventory(), 3,15,53, Arrays.asList(MAGIC_GEM.get(), MAGIC_BLOCK_ITEM.get()))); | ||
|
||
this.trackInt(fuel = new FunctionalIntReferenceHolder(() -> this.tileEntity.fuel, | ||
value -> this.tileEntity.fuel = value)); | ||
|
||
} | ||
//Client constructor | ||
public MagicPressContainer(final int windowID, final PlayerInventory playerInv, final PacketBuffer data) { | ||
this(windowID, playerInv, getTileEntity(playerInv, data)); | ||
} | ||
|
||
private static MagicPressTileEntity getTileEntity(final PlayerInventory playerInv, final PacketBuffer data) { | ||
Objects.requireNonNull(playerInv, "playerInv cannot be null"); | ||
Objects.requireNonNull(data, "data cannot be null"); | ||
final TileEntity tileAtPos = playerInv.player.world.getTileEntity(data.readBlockPos()); | ||
if (tileAtPos instanceof MagicPressTileEntity) { | ||
return (MagicPressTileEntity) tileAtPos; | ||
} | ||
throw new IllegalStateException("TileEntity is not correct " + tileAtPos); | ||
} | ||
|
||
@Override | ||
public boolean canInteractWith(PlayerEntity playerIn) { | ||
return isWithinUsableDistance(canInteractWithCallable, playerIn, RegistryHandler.MAGIC_PRESS.get()); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public ItemStack transferStackInSlot(final PlayerEntity player, final int index) { | ||
ItemStack returnStack = ItemStack.EMPTY; | ||
final Slot slot = this.inventorySlots.get(index); | ||
if (slot != null && slot.getHasStack()) { | ||
final ItemStack slotStack = slot.getStack(); | ||
returnStack = slotStack.copy(); | ||
|
||
final int containerSlots = this.inventorySlots.size() - player.inventory.mainInventory.size(); | ||
if (index < containerSlots) { | ||
if (!mergeItemStack(slotStack, containerSlots, this.inventorySlots.size(), true)) { | ||
return ItemStack.EMPTY; | ||
} | ||
} else if (!mergeItemStack(slotStack, 0, containerSlots, false)) { | ||
return ItemStack.EMPTY; | ||
} | ||
if (slotStack.getCount() == 0) { | ||
slot.putStack(ItemStack.EMPTY); | ||
} else { | ||
slot.onSlotChanged(); | ||
} | ||
if (slotStack.getCount() == returnStack.getCount()) { | ||
return ItemStack.EMPTY; | ||
} | ||
slot.onTake(player, slotStack); | ||
} | ||
return returnStack; | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public int getFuelScaled() { | ||
return this.fuel.get() != 0 && this.tileEntity.fuel != 0 ? this.fuel.get() * 112 / this.tileEntity.maxFuel : 0; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/pitheguy/magicmod/container/itemhandlers/MultiItemSlotItemHandler.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,22 @@ | ||
package com.pitheguy.magicmod.container.itemhandlers; | ||
|
||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.items.IItemHandler; | ||
import net.minecraftforge.items.SlotItemHandler; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public class MultiItemSlotItemHandler extends SlotItemHandler { | ||
final List<Item> validItem; | ||
public MultiItemSlotItemHandler(IItemHandler itemHandler, int index, int xPosition, int yPosition, List<Item> validItem) { | ||
super(itemHandler, index, xPosition, yPosition); | ||
this.validItem = validItem; | ||
} | ||
|
||
@Override | ||
public boolean isItemValid(@NotNull ItemStack stack) { | ||
return validItem.contains(stack.getItem()) && super.isItemValid(stack); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...gicinfuser/SingleItemSlotItemHandler.java → ...emhandlers/SingleItemSlotItemHandler.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
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
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
Oops, something went wrong.