Work on mimics as well as some structure tinkering.
This commit is contained in:
parent
545b50ac82
commit
546215ab37
31 changed files with 1183 additions and 5 deletions
133
src/main/java/wayoftime/bloodmagic/common/block/BlockMimic.java
Normal file
133
src/main/java/wayoftime/bloodmagic/common/block/BlockMimic.java
Normal file
|
@ -0,0 +1,133 @@
|
|||
package wayoftime.bloodmagic.common.block;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
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.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.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
import wayoftime.bloodmagic.tile.TileMimic;
|
||||
|
||||
public class BlockMimic extends Block
|
||||
{
|
||||
private static final VoxelShape SHAPE = VoxelShapes.create(0.01, 0, 0.01, 0.99, 1, 0.99);
|
||||
|
||||
public BlockMimic(Properties prop)
|
||||
{
|
||||
super(prop);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void addInformation(ItemStack stack, @Nullable IBlockReader reader, List<ITextComponent> list, ITooltipFlag flags)
|
||||
// {
|
||||
// list.add(new TranslationTextComponent("message.fancyblock"));
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public int getLightValue(BlockState state, IBlockReader world, BlockPos pos)
|
||||
// {
|
||||
// TileEntity te = world.getTileEntity(pos);
|
||||
// if (te instanceof TileMimic)
|
||||
// {
|
||||
// BlockState mimic = ((TileMimic) te).getMimic();
|
||||
// if (mimic != null && !(mimic.getBlock() instanceof BlockMimic))
|
||||
// {
|
||||
// return mimic.getLightValue(world, pos);
|
||||
// }
|
||||
// }
|
||||
// return super.getLightValue(state, world, pos);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader reader, BlockPos pos, ISelectionContext context)
|
||||
{
|
||||
TileEntity te = reader.getTileEntity(pos);
|
||||
if (te instanceof TileMimic)
|
||||
{
|
||||
BlockState mimic = ((TileMimic) te).getMimic();
|
||||
if (mimic != null && !(mimic.getBlock() instanceof BlockMimic))
|
||||
{
|
||||
return mimic.getShape(reader, pos, context);
|
||||
}
|
||||
}
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(BlockState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world)
|
||||
{
|
||||
return new TileMimic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult trace)
|
||||
{
|
||||
TileMimic mimic = (TileMimic) world.getTileEntity(pos);
|
||||
|
||||
return (mimic != null && mimic.onBlockActivated(world, pos, state, player, hand, player.getHeldItem(hand), trace.getFace()))
|
||||
? ActionResultType.SUCCESS
|
||||
: ActionResultType.FAIL;
|
||||
// ItemStack item = player.getHeldItem(hand);
|
||||
// if (!item.isEmpty() && item.getItem() instanceof BlockItem)
|
||||
// {
|
||||
// if (!world.isRemote)
|
||||
// {
|
||||
// TileEntity te = world.getTileEntity(pos);
|
||||
// if (te instanceof TileMimic)
|
||||
// {
|
||||
// BlockState mimicState = ((BlockItem) item.getItem()).getBlock().getDefaultState();
|
||||
// ((TileMimic) te).setMimic(mimicState);
|
||||
// }
|
||||
// }
|
||||
// return ActionResultType.SUCCESS;
|
||||
// }
|
||||
// return super.onBlockActivated(state, world, pos, player, hand, trace);
|
||||
}
|
||||
|
||||
// public boolean canMimicBlock(World world, BlockPos pos, BlockState state)
|
||||
// {
|
||||
// return state.getBlock()
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onPlayerDestroy(IWorld world, BlockPos blockPos, BlockState blockState)
|
||||
{
|
||||
TileMimic altar = (TileMimic) world.getTileEntity(blockPos);
|
||||
if (altar != null)
|
||||
altar.dropItems();
|
||||
|
||||
super.onPlayerDestroy(world, blockPos, blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving)
|
||||
{
|
||||
if (!state.isIn(newState.getBlock()))
|
||||
{
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
if (tileentity instanceof TileMimic)
|
||||
{
|
||||
((TileMimic) tileentity).dropItems();
|
||||
}
|
||||
|
||||
super.onReplaced(state, worldIn, pos, newState, isMoving);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package wayoftime.bloodmagic.common.block;
|
|||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.AbstractBlock.Properties;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FenceGateBlock;
|
||||
import net.minecraft.block.FlowingFluidBlock;
|
||||
import net.minecraft.block.RotatedPillarBlock;
|
||||
|
@ -17,6 +18,8 @@ import net.minecraft.item.BucketItem;
|
|||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraftforge.common.ToolType;
|
||||
import net.minecraftforge.common.extensions.IForgeContainerType;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
|
@ -98,6 +101,9 @@ public class BloodMagicBlocks
|
|||
public static final RegistryObject<Block> OBSIDIAN_PATH = BASICBLOCKS.register("obsidianbrickpath", () -> new BlockPath(8, AbstractBlock.Properties.create(Material.ROCK).hardnessAndResistance(2.0F, 5.0F).harvestTool(ToolType.PICKAXE).harvestLevel(3)));
|
||||
public static final RegistryObject<Block> OBSIDIAN_TILE_PATH = BASICBLOCKS.register("obsidiantilepath", () -> new BlockPath(8, AbstractBlock.Properties.create(Material.ROCK).hardnessAndResistance(2.0F, 5.0F).harvestTool(ToolType.PICKAXE).harvestLevel(3)));
|
||||
|
||||
public static final RegistryObject<Block> MIMIC = BLOCKS.register("mimic", () -> new BlockMimic(Properties.create(Material.IRON).sound(SoundType.METAL).hardnessAndResistance(2.0f).setOpaque(BloodMagicBlocks::isntSolid).setSuffocates(BloodMagicBlocks::isntSolid).setBlocksVision(BloodMagicBlocks::isntSolid).notSolid()));
|
||||
public static final RegistryObject<Block> ETHEREAL_MIMIC = BLOCKS.register("ethereal_mimic", () -> new BlockMimic(Properties.create(Material.IRON).sound(SoundType.METAL).hardnessAndResistance(2.0f).setOpaque(BloodMagicBlocks::isntSolid).setSuffocates(BloodMagicBlocks::isntSolid).setBlocksVision(BloodMagicBlocks::isntSolid).notSolid().doesNotBlockMovement()));
|
||||
|
||||
private static ForgeFlowingFluid.Properties makeProperties()
|
||||
{
|
||||
return new ForgeFlowingFluid.Properties(LIFE_ESSENCE_FLUID, LIFE_ESSENCE_FLUID_FLOWING, FluidAttributes.builder(FLUID_STILL, FLUID_FLOWING)).bucket(LIFE_ESSENCE_BUCKET).block(LIFE_ESSENCE_BLOCK);
|
||||
|
@ -142,6 +148,10 @@ public class BloodMagicBlocks
|
|||
public static final RegistryObject<Block> DUNGEON_BRICK_GATE = BLOCKS.register("dungeon_brick_gate", () -> new FenceGateBlock(Properties.create(Material.ROCK).hardnessAndResistance(2.0F, 5.0F).sound(SoundType.STONE).harvestTool(ToolType.PICKAXE).harvestLevel(2).setRequiresTool()));
|
||||
public static final RegistryObject<Block> DUNGEON_POLISHED_GATE = BLOCKS.register("dungeon_polished_gate", () -> new FenceGateBlock(Properties.create(Material.ROCK).hardnessAndResistance(2.0F, 5.0F).sound(SoundType.STONE).harvestTool(ToolType.PICKAXE).harvestLevel(2).setRequiresTool()));
|
||||
|
||||
private static boolean isntSolid(BlockState state, IBlockReader reader, BlockPos pos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//
|
||||
//// private static <T extends Block> RegistryObject<T> register(String name, Supplier<? extends T> sup, Function<RegistryObject<T>, Supplier<? extends Item>> itemCreator)
|
||||
//// {
|
||||
|
|
|
@ -79,6 +79,22 @@ public class GeneratorBlockStates extends BlockStateProvider
|
|||
buildPillarCap(BloodMagicBlocks.DUNGEON_PILLAR_CAP.get(), BloodMagic.rl("block/dungeon/dungeon_pillarheart"), BloodMagic.rl("block/dungeon/dungeon_pillarbottom"), BloodMagic.rl("block/dungeon/dungeon_pillartop"));
|
||||
|
||||
buildAssortedBlock(BloodMagicBlocks.DUNGEON_BRICK_ASSORTED.get(), modLoc("dungeon_brick1"), modLoc("dungeon_brick2"), modLoc("dungeon_brick3"));
|
||||
|
||||
buildCubeAllWithTextureName("etherealopaquemimic");
|
||||
buildCubeAllWithTextureName("sentientmimic");
|
||||
buildCubeAllWithTextureName("solidclearmimic");
|
||||
buildCubeAllWithTextureName("solidlightmimic");
|
||||
buildCubeAllWithTextureName("solidopaquemimic");
|
||||
}
|
||||
|
||||
// private void buildCustomLoader(Block block)
|
||||
// {
|
||||
// ModelFile modelFile = models().crop("", null);
|
||||
// }
|
||||
|
||||
private void buildCubeAllWithTextureName(String texture)
|
||||
{
|
||||
models().cubeAll(texture, BloodMagic.rl("block/" + texture)).assertExistence();
|
||||
}
|
||||
|
||||
private void buildAssortedBlock(Block block, ResourceLocation... modelResources)
|
||||
|
|
|
@ -82,6 +82,14 @@ public class GeneratorItemModels extends ItemModelProvider
|
|||
registerDemonTool(BloodMagicItems.SENTIENT_SHOVEL.get());
|
||||
registerSacrificialKnife(BloodMagicItems.SACRIFICIAL_DAGGER.get());
|
||||
|
||||
registerCustomFullTexture(BloodMagicBlocks.MIMIC.get(), "solidopaquemimic");
|
||||
registerCustomFullTexture(BloodMagicBlocks.ETHEREAL_MIMIC.get(), "etherealopaquemimic");
|
||||
}
|
||||
|
||||
private void registerCustomFullTexture(Block block, String texturePath)
|
||||
{
|
||||
String path = block.getRegistryName().getPath();
|
||||
getBuilder(path).parent(new ModelFile.UncheckedModelFile(modLoc("block/" + texturePath)));
|
||||
}
|
||||
|
||||
private void registerCustomBlockPath(Block block, String newPath)
|
||||
|
|
|
@ -15,7 +15,9 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.LootTableProvider;
|
||||
import net.minecraft.data.loot.BlockLootTables;
|
||||
import net.minecraft.data.loot.ChestLootTables;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.loot.ConstantRange;
|
||||
import net.minecraft.loot.ItemLootEntry;
|
||||
import net.minecraft.loot.LootParameterSet;
|
||||
|
@ -26,6 +28,7 @@ import net.minecraft.loot.LootTableManager;
|
|||
import net.minecraft.loot.ValidationTracker;
|
||||
import net.minecraft.loot.conditions.BlockStateProperty;
|
||||
import net.minecraft.loot.conditions.ILootCondition;
|
||||
import net.minecraft.loot.functions.EnchantWithLevels;
|
||||
import net.minecraft.loot.functions.SetCount;
|
||||
import net.minecraft.state.Property;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
@ -47,7 +50,27 @@ public class GeneratorLootTable extends LootTableProvider
|
|||
@Override
|
||||
protected List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootParameterSet>> getTables()
|
||||
{
|
||||
return ImmutableList.of(Pair.of(BMBlocks::new, LootParameterSets.BLOCK));
|
||||
return ImmutableList.of(Pair.of(BMBlocks::new, LootParameterSets.BLOCK), Pair.of(BMLootTables::new, LootParameterSets.CHEST));
|
||||
}
|
||||
|
||||
private static class BMLootTables extends ChestLootTables
|
||||
{
|
||||
@Override
|
||||
public void accept(BiConsumer<ResourceLocation, LootTable.Builder> acceptor)
|
||||
{
|
||||
acceptor.accept(BloodMagic.rl("test"), testLootTableGeneration());
|
||||
}
|
||||
|
||||
private LootTable.Builder testLootTableGeneration()
|
||||
{
|
||||
LootTable.Builder table = LootTable.builder();
|
||||
LootPool.Builder pool = LootPool.builder().name("test").addEntry(ItemLootEntry.builder(Items.BOOK).weight(10).acceptFunction(EnchantWithLevels.func_215895_a(ConstantRange.of(30)).func_216059_e()));
|
||||
|
||||
table.addLootPool(pool);
|
||||
// table.build();
|
||||
|
||||
return table;
|
||||
}
|
||||
}
|
||||
|
||||
private static class BMBlocks extends BlockLootTables
|
||||
|
@ -100,6 +123,10 @@ public class GeneratorLootTable extends LootTableProvider
|
|||
registerDropSelfLootTable(BloodMagicBlocks.DUNGEON_POLISHED_WALL.get());
|
||||
registerDropSelfLootTable(BloodMagicBlocks.DUNGEON_BRICK_GATE.get());
|
||||
registerDropSelfLootTable(BloodMagicBlocks.DUNGEON_POLISHED_GATE.get());
|
||||
|
||||
registerDropSelfLootTable(BloodMagicBlocks.MIMIC.get());
|
||||
registerDropSelfLootTable(BloodMagicBlocks.ETHEREAL_MIMIC.get());
|
||||
|
||||
}
|
||||
|
||||
private void registerNoDropLootTable(Block block)
|
||||
|
|
|
@ -10,6 +10,7 @@ import wayoftime.bloodmagic.BloodMagic;
|
|||
import wayoftime.bloodmagic.common.block.BloodMagicBlocks;
|
||||
import wayoftime.bloodmagic.common.item.arc.ItemARCToolBase;
|
||||
import wayoftime.bloodmagic.common.item.block.ItemBlockAlchemyTable;
|
||||
import wayoftime.bloodmagic.common.item.block.ItemBlockMimic;
|
||||
import wayoftime.bloodmagic.common.item.sigil.ItemSigilAir;
|
||||
import wayoftime.bloodmagic.common.item.sigil.ItemSigilBloodLight;
|
||||
import wayoftime.bloodmagic.common.item.sigil.ItemSigilDivination;
|
||||
|
@ -90,6 +91,9 @@ public class BloodMagicItems
|
|||
public static final RegistryObject<Item> OBSIDIAN_PATH_ITEM = ITEMS.register("obsidianbrickpath", () -> new BlockItem(BloodMagicBlocks.OBSIDIAN_PATH.get(), new Item.Properties().group(BloodMagic.TAB)));
|
||||
public static final RegistryObject<Item> OBSIDIAN_TILE_PATH_ITEM = ITEMS.register("obsidiantilepath", () -> new BlockItem(BloodMagicBlocks.OBSIDIAN_TILE_PATH.get(), new Item.Properties().group(BloodMagic.TAB)));
|
||||
|
||||
public static final RegistryObject<Item> MIMIC_ITEM = ITEMS.register("mimic", () -> new ItemBlockMimic(BloodMagicBlocks.MIMIC.get(), new Item.Properties().group(BloodMagic.TAB)));
|
||||
public static final RegistryObject<Item> MIMIC_ETHEREAL_ITEM = ITEMS.register("ethereal_mimic", () -> new ItemBlockMimic(BloodMagicBlocks.ETHEREAL_MIMIC.get(), new Item.Properties().group(BloodMagic.TAB)));
|
||||
|
||||
// TODO: Need to rework the above instantiations for the ItemBlocks so that it's
|
||||
// done with the Blocks.
|
||||
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
package wayoftime.bloodmagic.common.item.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.ChestTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import wayoftime.bloodmagic.tile.TileMimic;
|
||||
|
||||
public class ItemBlockMimic extends BlockItem
|
||||
{
|
||||
public ItemBlockMimic(Block block, Properties prop)
|
||||
{
|
||||
super(block, prop);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType tryPlace(BlockItemUseContext context)
|
||||
{
|
||||
PlayerEntity player = context.getPlayer();
|
||||
ItemStack stack = player.getHeldItem(context.getHand());
|
||||
|
||||
// If not sneaking, do normal item use
|
||||
if (!player.isSneaking())
|
||||
{
|
||||
return super.tryPlace(context);
|
||||
}
|
||||
|
||||
BlockPos pos = context.getPos().offset(context.getFace().getOpposite());
|
||||
World world = context.getWorld();
|
||||
Direction direction = context.getFace();
|
||||
|
||||
// IF sneaking and player has permission, replace the targeted block
|
||||
if (player.canPlayerEdit(pos, direction, stack))
|
||||
{
|
||||
// Store information about the block being replaced and its appropriate
|
||||
// itemstack
|
||||
BlockState replacedBlockstate = world.getBlockState(pos);
|
||||
Block replacedBlock = replacedBlockstate.getBlock();
|
||||
ItemStack replacedStack = replacedBlock.getItem(world, pos, replacedBlockstate);
|
||||
|
||||
// Get the state for the mimic
|
||||
BlockState mimicBlockstate = this.getBlock().getDefaultState();
|
||||
|
||||
// Check if the block can be replaced
|
||||
|
||||
if (!canReplaceBlock(world, pos, replacedBlockstate))
|
||||
{
|
||||
return super.tryPlace(context);
|
||||
}
|
||||
|
||||
// Check if the tile entity, if any, can be replaced
|
||||
TileEntity tileReplaced = world.getTileEntity(pos);
|
||||
if (!canReplaceTile(tileReplaced))
|
||||
{
|
||||
return ActionResultType.FAIL;
|
||||
}
|
||||
|
||||
// If tile can be replaced, store info about the tile
|
||||
CompoundNBT tileTag = getTagFromTileEntity(tileReplaced);
|
||||
if (tileReplaced != null)
|
||||
{
|
||||
CompoundNBT voidTag = new CompoundNBT();
|
||||
voidTag.putInt("x", pos.getX());
|
||||
voidTag.putInt("y", pos.getY());
|
||||
voidTag.putInt("z", pos.getZ());
|
||||
tileReplaced.deserializeNBT(voidTag);
|
||||
}
|
||||
|
||||
// Remove one item from stack
|
||||
stack.shrink(1);
|
||||
|
||||
// Replace the block
|
||||
world.setBlockState(pos, mimicBlockstate, 3);
|
||||
// Make placing sound
|
||||
SoundType soundtype = mimicBlockstate.getSoundType(world, pos, context.getPlayer());
|
||||
world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
|
||||
|
||||
// Replace the tile entity
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile instanceof TileMimic)
|
||||
{
|
||||
TileMimic mimic = (TileMimic) tile;
|
||||
mimic.tileTag = tileTag;
|
||||
// mimic.setReplacedState(replacedBlockstate);
|
||||
mimic.setMimic(replacedBlockstate);
|
||||
mimic.setInventorySlotContents(0, replacedStack);
|
||||
mimic.refreshTileEntity();
|
||||
|
||||
if (player.isCreative())
|
||||
{
|
||||
mimic.dropItemsOnBreak = false;
|
||||
}
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
return ActionResultType.FAIL;
|
||||
|
||||
}
|
||||
|
||||
public boolean canReplaceTile(TileEntity tile)
|
||||
{
|
||||
if (tile instanceof ChestTileEntity)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return tile == null;
|
||||
}
|
||||
|
||||
public boolean canReplaceBlock(World world, BlockPos pos, BlockState state)
|
||||
{
|
||||
return state.getBlockHardness(world, pos) != -1.0F;
|
||||
}
|
||||
|
||||
public CompoundNBT getTagFromTileEntity(TileEntity tile)
|
||||
{
|
||||
CompoundNBT tag = new CompoundNBT();
|
||||
|
||||
if (tile != null)
|
||||
{
|
||||
return tile.write(tag);
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue