Skip to content

Commit

Permalink
Merge pull request #19 from PssbleTrngle/develop
Browse files Browse the repository at this point in the history
Brazier Indicator & Bug Fix
  • Loading branch information
PssbleTrngle authored Aug 28, 2020
2 parents cb8c4dd + f8425c4 commit b606a74
Show file tree
Hide file tree
Showing 27 changed files with 346 additions and 125 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ run
forge*changelog.txt

.bat
**.propertiesr
**.propertiesr

src/generated/
7 changes: 0 additions & 7 deletions src/generated/resources/.cache/cache

This file was deleted.

10 changes: 0 additions & 10 deletions src/generated/resources/assets/brazier/blockstates/brazier.json

This file was deleted.

This file was deleted.

31 changes: 0 additions & 31 deletions src/generated/resources/data/brazier/advancements/brazier.json

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions src/generated/resources/data/brazier/recipes/brazier.json

This file was deleted.

26 changes: 20 additions & 6 deletions src/main/java/com/possible_triangle/brazier/Content.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.possible_triangle.brazier;

import com.possible_triangle.brazier.block.BrazierBlock;
import com.possible_triangle.brazier.block.LazyTorchBlock;
import com.possible_triangle.brazier.block.LazyWallTorchBlock;
import com.possible_triangle.brazier.block.tile.BrazierTile;
import com.possible_triangle.brazier.block.tile.render.BrazierRenderer;
import com.possible_triangle.brazier.entity.Crazed;
import com.possible_triangle.brazier.entity.CrazedFlame;
import com.possible_triangle.brazier.entity.render.CrazedFlameRenderer;
import com.possible_triangle.brazier.entity.render.CrazedRender;
import com.possible_triangle.brazier.item.BrazierIndicator;
import com.possible_triangle.brazier.item.Flame;
import com.possible_triangle.brazier.item.LivingTorch;
import com.possible_triangle.brazier.particle.FlameParticle;
import net.minecraft.block.Block;
import net.minecraft.block.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.RenderTypeLookup;
Expand All @@ -21,6 +25,7 @@
import net.minecraft.item.ItemGroup;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.particles.BasicParticleType;
import net.minecraft.particles.IParticleData;
import net.minecraft.particles.ParticleType;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.EntityTypeTags;
Expand All @@ -41,6 +46,7 @@

import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class Content {
Expand All @@ -55,12 +61,18 @@ public class Content {
public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, Brazier.MODID);
public static final DeferredRegister<ParticleType<?>> PARTICLES = DeferredRegister.create(ForgeRegistries.PARTICLE_TYPES, Brazier.MODID);

public static final RegistryObject<BasicParticleType> FLAME_PARTICLE = PARTICLES.register("flame", () -> new BasicParticleType(false));

public static final RegistryObject<BrazierBlock> BRAZIER = registerBlock("brazier", BrazierBlock::new, p -> p.group(ItemGroup.DECORATIONS));
public static final RegistryObject<TileEntityType<BrazierTile>> BRAZIER_TILE = TILES.register("brazier", () ->
TileEntityType.Builder.create(BrazierTile::new, BRAZIER.get()).build(null)
TileEntityType.Builder.create(BrazierTile::new, BRAZIER.get()).build(null)
);

public static final RegistryObject<Block> LIVING_TORCH_BLOCK = BLOCKS.register("living_torch", () -> new LazyTorchBlock(FLAME_PARTICLE));
public static final RegistryObject<Block> LIVING_TORCH_BLOCK_WALL = BLOCKS.register("living_wall_torch", () -> new LazyWallTorchBlock(FLAME_PARTICLE));

public static final RegistryObject<Item> LIVING_FLAME = ITEMS.register("living_flame", Flame::new);
public static final RegistryObject<Item> LIVING_TORCH = ITEMS.register("living_torch", LivingTorch::new);

public static final RegistryObject<EntityType<Crazed>> CRAZED = ENTITIES.register("crazed", () -> EntityType.Builder.<Crazed>create(Crazed::new, EntityClassification.MONSTER)
.setCustomClientFactory((s, w) -> new Crazed(w))
Expand All @@ -72,9 +84,7 @@ public class Content {
.setShouldReceiveVelocityUpdates(false)
.immuneToFire().build("crazed_flame"));

public static final RegistryObject<BasicParticleType> FLAME_PARTICLE = PARTICLES.register("flame", () -> new BasicParticleType(false));

public static <B extends Block> RegistryObject<B> registerBlock(String name, Supplier<B> supplier, Function<Item.Properties,Item.Properties> props) {
public static <B extends Block> RegistryObject<B> registerBlock(String name, Supplier<B> supplier, Function<Item.Properties, Item.Properties> props) {
RegistryObject<B> block = BLOCKS.register(name, supplier);
ITEMS.register(name, () -> new BlockItem(block.get(), props.apply(new Item.Properties())));
return block;
Expand Down Expand Up @@ -106,7 +116,11 @@ public static void clientSetup(Minecraft mc) {
CRAZED.ifPresent(type -> mc.getRenderManager().register(type, new CrazedRender(mc.getRenderManager())));
CRAZED_FLAME.ifPresent(type -> mc.getRenderManager().register(type, new CrazedFlameRenderer(mc.getRenderManager())));

BRAZIER.ifPresent(b -> RenderTypeLookup.setRenderLayer(b, RenderType.getCutout()));
Stream.of(BRAZIER, LIVING_TORCH_BLOCK, LIVING_TORCH_BLOCK_WALL)
.filter(RegistryObject::isPresent)
.map(RegistryObject::get)
.forEach(b -> RenderTypeLookup.setRenderLayer(b, RenderType.getCutout()));

BRAZIER_TILE.ifPresent(tile -> ClientRegistry.bindTileEntityRenderer(tile, BrazierRenderer::new));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.gson.internal.$Gson$Preconditions;
import com.possible_triangle.brazier.Content;
import com.possible_triangle.brazier.block.tile.BrazierTile;
import net.minecraft.block.*;
Expand All @@ -12,13 +13,20 @@
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.monster.MonsterEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.DamageSource;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
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.world.IBlockReader;
Expand All @@ -35,6 +43,7 @@
public class BrazierBlock extends ContainerBlock {

public static final BooleanProperty LIT = BlockStateProperties.LIT;
public static final Ingredient TORCH_INPUT = Ingredient.fromItems(Items.TORCH, Blocks.field_235339_cQ_);

public BrazierBlock() {
super(Properties.create(Material.IRON)
Expand Down Expand Up @@ -90,10 +99,25 @@ public TileEntity createNewTileEntity(IBlockReader worldIn) {
return new BrazierTile();
}

@Override
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
return Content.LIVING_TORCH.filter(torch -> {
ItemStack stack = player.getHeldItem(hand);
if (TORCH_INPUT.test(stack)) {
if (!player.isCreative()) stack.shrink(1);
player.addItemStackToInventory(new ItemStack(torch, 1));
return true;
}
return false;
}).map($ -> ActionResultType.SUCCESS).orElse(ActionResultType.PASS);
}

@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}

@Override
public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entity) {
if (!entity.func_230279_az_() && state.get(LIT) && entity instanceof LivingEntity && !EnchantmentHelper.hasFrostWalker((LivingEntity) entity)) {
entity.attackEntityFrom(DamageSource.IN_FIRE, 2F);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.possible_triangle.brazier.block;

import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.TorchBlock;
import net.minecraft.particles.IParticleData;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.util.Random;
import java.util.function.Supplier;

public class LazyTorchBlock extends TorchBlock {

private final Supplier<? extends IParticleData> particle;

public LazyTorchBlock(Supplier<? extends IParticleData> particle) {
super(Properties.from(Blocks.TORCH), null);
this.particle = particle;
}

@OnlyIn(Dist.CLIENT)
@Override
public void animateTick(BlockState state, World world, BlockPos pos, Random rand) {
double d0 = (double)pos.getX() + 0.5D;
double d1 = (double)pos.getY() + 0.7D;
double d2 = (double)pos.getZ() + 0.5D;
world.addParticle(ParticleTypes.SMOKE, d0, d1, d2, 0.0D, 0.0D, 0.0D);
world.addParticle(this.particle.get(), d0, d1, d2, 0.0D, 0.0D, 0.0D);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.possible_triangle.brazier.block;

import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.TorchBlock;
import net.minecraft.block.WallTorchBlock;
import net.minecraft.particles.IParticleData;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.util.Random;
import java.util.function.Supplier;

public class LazyWallTorchBlock extends WallTorchBlock {

private final Supplier<? extends IParticleData> particle;

public LazyWallTorchBlock(Supplier<? extends IParticleData> particle) {
super(Properties.from(Blocks.WALL_TORCH), null);
this.particle = particle;
}

@OnlyIn(Dist.CLIENT)
@Override
public void animateTick(BlockState state, World world, BlockPos pos, Random rand) {
double d0 = (double)pos.getX() + 0.5D;
double d1 = (double)pos.getY() + 0.7D;
double d2 = (double)pos.getZ() + 0.5D;
world.addParticle(ParticleTypes.SMOKE, d0, d1, d2, 0.0D, 0.0D, 0.0D);
world.addParticle(this.particle.get(), d0, d1, d2, 0.0D, 0.0D, 0.0D);
}

}
Loading

0 comments on commit b606a74

Please sign in to comment.