Skip to content

Commit 5bb57a3

Browse files
committed
Merge branch 'Developer'
2 parents 5457be6 + c8b58e0 commit 5bb57a3

25 files changed

+394
-362
lines changed

src/main/java/com/dani/blacksmithmod/blocks/Anvil.java

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,38 @@
22

33
import com.dani.blacksmithmod.BlacksmithMod;
44
import com.dani.blacksmithmod.items.Hammer;
5-
import com.dani.blacksmithmod.tiles.anviltileentity.AnvilTileEntity;
5+
import com.dani.blacksmithmod.setup.TileEntityRegister;
6+
import com.dani.blacksmithmod.tiles.AnvilTileEntity;
67
import net.minecraft.block.*;
78
import net.minecraft.block.material.Material;
89
import net.minecraft.entity.player.PlayerEntity;
910
import net.minecraft.entity.player.ServerPlayerEntity;
1011
import net.minecraft.inventory.container.INamedContainerProvider;
11-
import net.minecraft.state.DirectionProperty;
1212
import net.minecraft.tileentity.TileEntity;
1313
import net.minecraft.util.*;
1414
import net.minecraft.util.math.BlockPos;
1515
import net.minecraft.util.math.BlockRayTraceResult;
1616
import net.minecraft.util.math.shapes.ISelectionContext;
1717
import net.minecraft.util.math.shapes.VoxelShape;
1818
import net.minecraft.util.math.shapes.VoxelShapes;
19-
import net.minecraft.util.text.TranslationTextComponent;
2019
import net.minecraft.world.IBlockReader;
2120
import net.minecraft.world.World;
2221
import net.minecraftforge.common.ToolType;
2322
import net.minecraftforge.fml.network.NetworkHooks;
2423

2524
import javax.annotation.Nullable;
2625

26+
27+
/**
28+
* Anvil block, this blocks is used to craft items from blacksmith mod and minecraft vanilla
29+
*/
2730
public class Anvil extends Block {
2831

32+
//VoxelShape for the anvil block.
2933
private static final VoxelShape PART_BASE = Block.makeCuboidShape(1.0D, 0.0D, 1.0D, 15.0D, 4.0D, 15.0D);
3034
private static final VoxelShape PART_LOWER_X = Block.makeCuboidShape(3.0D, 4.0D, 3.0D, 13.0D, 5.0D, 13.0D);
3135
private static final VoxelShape PART_MID_X = Block.makeCuboidShape(4.0D, 5.0D, 4.0D, 12.0D, 10.0D, 12.0D);
3236
private static final VoxelShape PART_UPPER_X = Block.makeCuboidShape(1.0D, 10.0D, 1.0D, 15.0D, 15.0D, 15.0D);
33-
3437
private static final VoxelShape X_AXIS_AABB = VoxelShapes.or(PART_BASE, PART_LOWER_X, PART_MID_X, PART_UPPER_X);
3538

3639

@@ -41,67 +44,83 @@ public Anvil() {
4144
.harvestLevel(1)
4245
.harvestTool(ToolType.PICKAXE));
4346
this.setRegistryName(BlacksmithMod.MODID,"anvil");
44-
4547
}
4648

4749
/**
48-
* Verifica si este blqoue tiene un TileEntity
49-
* @param state Estado del bloque
50-
* @return Retorna TRUE, porque posee un tileEntity
50+
* Verify if this block has TileEntity
51+
* @param state Block state
52+
* @return True, it has TileEntity
5153
*/
5254
@Override
5355
public boolean hasTileEntity(BlockState state) {
5456
return true;
5557
}
5658

5759
/**
58-
* Este metodo crea el tileEntity al bloque
59-
* @param state Estado del bloque
60-
* @param world Mundo donde esta el bloque
61-
* @return retorna un AnvilTileEntity
60+
* This method make a TileEntity to Anvil Block
61+
* @param state Block state
62+
* @param world World where it's.
63+
* @return new AnvilTileEntity object.
6264
*/
6365
@Nullable
6466
@Override
6567
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
66-
return new AnvilTileEntity();
68+
return TileEntityRegister.ANVIL_TILE_ENTITY.create();
6769
}
6870

71+
/**
72+
* Create a custom VoxelShape
73+
* @param state Block state
74+
* @param worldIn World Render
75+
* @param pos Block position
76+
* @param context Context
77+
* @return Custom VoxelShape
78+
*/
6979
@Override
7080
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
71-
7281
return X_AXIS_AABB;
7382
}
7483

84+
/**
85+
* When the player use right click in it
86+
* @param state Block State
87+
* @param worldIn World where player and block stay
88+
* @param pos Block position
89+
* @param player Player who interact
90+
* @param handIn what had use
91+
* @param hit where the player hit the block
92+
* @return interaction result
93+
*/
7594
@Override
7695
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit){
77-
if(worldIn.isRemote)
78-
return ActionResultType.PASS;
79-
80-
TileEntity tileEntity = worldIn.getTileEntity(pos);
81-
if (tileEntity instanceof INamedContainerProvider) {
82-
NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity, tileEntity.getPos());
96+
if(!worldIn.isRemote()){ //when is True is Client side, and if is false es serve side
97+
TileEntity tileEntity = worldIn.getTileEntity(pos);
98+
if( tileEntity instanceof INamedContainerProvider)
99+
NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity, tileEntity.getPos());
100+
return ActionResultType.SUCCESS;
83101
}
84-
return ActionResultType.SUCCESS;
102+
return ActionResultType.PASS;
85103
}
86104

87-
// Cuando es True isremote() es el Cliente y si es False es El servidor
105+
/**
106+
* When the player use left click in it
107+
* @param state Block State
108+
* @param worldIn World where player and block stay
109+
* @param pos lock position
110+
* @param player Player who interact
111+
*/
88112
@Override
89113
public void onBlockClicked(BlockState state, World worldIn, BlockPos pos, PlayerEntity player) {
90-
if(!worldIn.isRemote()){
91-
if(player.inventory.getCurrentItem().getItem() instanceof Hammer){
114+
if (player.inventory.getCurrentItem().getItem() instanceof Hammer){
115+
if(!worldIn.isRemote()){ //server Side
92116
player.inventory.getCurrentItem().getItem().setDamage(player.inventory.getCurrentItem(),1);
93117
TileEntity tileEntity = worldIn.getTileEntity(pos);
94-
if(tileEntity instanceof AnvilTileEntity){
95-
118+
if(tileEntity instanceof AnvilTileEntity)
96119
((AnvilTileEntity) tileEntity).addHit();
97-
}
98-
}
99-
}
100120

101-
if(player.inventory.getCurrentItem().getItem() instanceof Hammer && worldIn.isRemote()){
102-
worldIn.playSound(player.getPosX(),player.getPosY(),player.getPosZ(),SoundType.ANVIL.getPlaceSound(), SoundCategory.BLOCKS,1.0f,1.0f,true);
121+
}else //client side
122+
worldIn.playSound(player.getPosX(),player.getPosY(),player.getPosZ(),SoundType.ANVIL.getPlaceSound(), SoundCategory.BLOCKS,1.0f,1.0f,true);
103123
}
104-
105-
106124
}
125+
107126
}

src/main/java/com/dani/blacksmithmod/containers/anvil/AnvilContainer.java renamed to src/main/java/com/dani/blacksmithmod/containers/AnvilContainer.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,30 @@
1-
package com.dani.blacksmithmod.containers.anvil;
1+
package com.dani.blacksmithmod.containers;
22

3-
import com.dani.blacksmithmod.containers.anvil.slot.IngredientSlot;
4-
import com.dani.blacksmithmod.containers.anvil.slot.OutputSlot;
3+
import com.dani.blacksmithmod.objects.IngredientSlot;
54
import com.dani.blacksmithmod.setup.BlockRegister;
65
import com.dani.blacksmithmod.setup.ContainerRegister;
7-
import com.dani.blacksmithmod.tiles.anviltileentity.AnvilTileEntity;
6+
import com.dani.blacksmithmod.tiles.AnvilTileEntity;
87
import net.minecraft.entity.player.PlayerEntity;
98
import net.minecraft.entity.player.PlayerInventory;
10-
import net.minecraft.inventory.IInventory;
119
import net.minecraft.inventory.container.Container;
1210
import net.minecraft.inventory.container.Slot;
1311
import net.minecraft.item.ItemStack;
1412
import net.minecraft.util.IWorldPosCallable;
1513
import net.minecraft.util.math.BlockPos;
1614
import net.minecraft.world.World;
17-
import net.minecraftforge.items.IItemHandler;
1815
import net.minecraftforge.items.ItemStackHandler;
19-
import net.minecraftforge.items.wrapper.InvWrapper;
2016

2117
public class AnvilContainer extends Container {
2218

2319
private AnvilTileEntity tileEntity;
2420
private PlayerEntity playerEntity;
25-
private IItemHandler playerInventory;
26-
2721
private ItemStackHandler ingredients;
28-
private ItemStackHandler output;
2922

3023
public AnvilContainer(int windowId, World world, BlockPos pos, PlayerInventory playerInventory, PlayerEntity player) {
3124
super(ContainerRegister.ANVIL_CONTAINER, windowId);
32-
3325
tileEntity = (AnvilTileEntity) world.getTileEntity(pos);
34-
35-
this.ingredients = tileEntity.materials;
36-
this.output = tileEntity.output;
37-
38-
26+
this.ingredients = tileEntity.getMaterials();
3927
this.playerEntity = player;
40-
this.playerInventory = new InvWrapper(playerInventory);
41-
4228
this.addPlayerSlots(playerInventory);
4329
this.anvilSlots();
4430

@@ -94,12 +80,10 @@ private void addPlayerSlots(final PlayerInventory playerInventory) {
9480
* Agrega los Slots de la interfaz
9581
*/
9682
private void anvilSlots(){
97-
this.addSlot(new OutputSlot(this.output, 0, 136, 33));
98-
9983
int index = 0;
10084
for (int row = 0; row < 3; ++row) {
10185
for (int col = 0; col < 3; ++col) {
102-
this.addSlot(new IngredientSlot(this.ingredients, index, 15 + col * 18, 16+ row * 18));
86+
this.addSlot(new IngredientSlot(this.ingredients, index, 62 + col * 18, 14 + row * 18));
10387
++index;
10488
}
10589
}

src/main/java/com/dani/blacksmithmod/containers/anvil/slot/OutputSlot.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/main/java/com/dani/blacksmithmod/containers/anvilcrafting/AnvilCrafting.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/main/java/com/dani/blacksmithmod/items/itemabstract/Recipe.java

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,30 @@
88
import net.minecraft.item.crafting.IRecipeType;
99
import net.minecraft.util.ResourceLocation;
1010
import net.minecraft.world.World;
11+
import net.minecraftforge.items.ItemStackHandler;
1112

12-
public abstract class Recipe implements IRecipe {
13+
public abstract class Recipe{
1314
protected final Item[] recipe;
1415

1516
public Recipe(Item[] recipe){
1617
this.recipe = recipe;
1718
}
1819

19-
@Override
20-
public boolean matches(IInventory inv, World worldIn) {
21-
for(int i = 0;i < inv.getSizeInventory();i++)
22-
if(inv.getStackInSlot(i).getItem() != recipe[i])
20+
21+
public boolean matches(ItemStackHandler handler, World worldIn) {
22+
System.out.println("hello matches!!");
23+
for(int i = 0;i < handler.getSlots();i++)
24+
if(handler.getStackInSlot(i).getItem() != recipe[i])
2325
return false;
2426
return true;
2527
}
2628

27-
@Override
28-
public abstract ItemStack getCraftingResult(IInventory inv);
29-
30-
@Override
31-
public boolean canFit(int width, int height) {
32-
return false;
29+
public ItemStack decrStackSize(ItemStack stack,int count){
30+
if(stack.getCount() < count)
31+
return stack;
32+
stack.setCount(stack.getCount()-count);
33+
return stack;
3334
}
3435

35-
@Override
36-
public ItemStack getRecipeOutput() {
37-
return null;
38-
}
39-
40-
@Override
41-
public ResourceLocation getId() {
42-
return null;
43-
}
44-
45-
@Override
46-
public IRecipeSerializer<?> getSerializer() {
47-
return null;
48-
}
49-
50-
@Override
51-
public IRecipeType<?> getType() {
52-
return null;
53-
}
36+
public abstract ItemStack getCraftingResult(ItemStackHandler inv);
5437
}

src/main/java/com/dani/blacksmithmod/items/recipes/DiamondHorseArmorRecipe.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.item.Item;
77
import net.minecraft.item.ItemStack;
88
import net.minecraft.item.Items;
9+
import net.minecraftforge.items.ItemStackHandler;
910

1011
public class DiamondHorseArmorRecipe extends Recipe {
1112

@@ -19,15 +20,15 @@ public DiamondHorseArmorRecipe() {
1920
}
2021

2122
@Override
22-
public ItemStack getCraftingResult(IInventory inv) {
23-
inv.decrStackSize(0,1);
24-
inv.decrStackSize(2,1);
25-
inv.decrStackSize(3,1);
26-
inv.decrStackSize(4,1);
27-
inv.decrStackSize(5,1);
28-
inv.decrStackSize(6,1);
29-
inv.decrStackSize(8,1);
30-
return new ItemStack(Items.DIAMOND_HORSE_ARMOR);
23+
public ItemStack getCraftingResult(ItemStackHandler inv) {
24+
inv.extractItem(0,1,false);
25+
inv.extractItem(2,1,false);
26+
inv.extractItem(3,1,false);
27+
inv.extractItem(4,1,false);
28+
inv.extractItem(5,1,false);
29+
inv.extractItem(6,1,false);
30+
inv.extractItem(8,1,false);
31+
return new ItemStack(Items.DIAMOND_HORSE_ARMOR,1);
3132
}
3233

3334
}

src/main/java/com/dani/blacksmithmod/items/recipes/DiamondShieldRecipe.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.item.Item;
77
import net.minecraft.item.ItemStack;
88
import net.minecraft.item.Items;
9+
import net.minecraftforge.items.ItemStackHandler;
910

1011
public class DiamondShieldRecipe extends Recipe {
1112

@@ -18,13 +19,13 @@ public DiamondShieldRecipe() {
1819
});
1920
}
2021

22+
2123
@Override
22-
public ItemStack getCraftingResult(IInventory inv) {
23-
inv.decrStackSize(1,1);
24-
inv.decrStackSize(3,1);
25-
inv.decrStackSize(5,1);
26-
inv.decrStackSize(7,1);
27-
return new ItemStack(ItemRegister.GOLD_SHIELD);
24+
public ItemStack getCraftingResult(ItemStackHandler inv) {
25+
inv.extractItem(1,1,false);
26+
inv.extractItem(3,1,false);
27+
inv.extractItem(5,1,false);
28+
inv.extractItem(7,1,false);
29+
return new ItemStack(ItemRegister.DIAMOND_SHIELD,1);
2830
}
29-
3031
}

0 commit comments

Comments
 (0)