Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #33

Merged
merged 5 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions src/main/java/com/possible_triangle/brazier/Content.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
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.SpawnPowder;
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.Flame;
import com.possible_triangle.brazier.item.LazySpawnEgg;
import com.possible_triangle.brazier.item.LivingTorch;
import com.possible_triangle.brazier.particle.FlameParticle;
Expand All @@ -23,6 +23,7 @@
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.Rarity;
import net.minecraft.particles.BasicParticleType;
import net.minecraft.particles.ParticleType;
import net.minecraft.tags.BlockTags;
Expand All @@ -49,19 +50,24 @@
import java.util.function.Supplier;
import java.util.stream.Stream;

import static com.possible_triangle.brazier.Brazier.MODID;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class Content {

public static final ITag<Block> BRAZIER_BASE_BLOCKS = BlockTags.makeWrapperTag(new ResourceLocation(Brazier.MODID, "brazier_base_blocks").toString());
public static final ITag<EntityType<?>> BRAZIER_WHITELIST = EntityTypeTags.func_232896_a_(new ResourceLocation(Brazier.MODID, "brazier_whitelist").toString());
public static final ITag<EntityType<?>> BRAZIER_BLACKLIST = EntityTypeTags.func_232896_a_(new ResourceLocation(Brazier.MODID, "brazier_blacklist").toString());
public static final ITag<Item> TORCHES = ItemTags.makeWrapperTag(new ResourceLocation(Brazier.MODID, "torches").toString());
public static final ITag<Block> BRAZIER_BASE_BLOCKS = BlockTags.makeWrapperTag(new ResourceLocation(MODID, "brazier_base_blocks").toString());
public static final ITag<EntityType<?>> BRAZIER_WHITELIST = EntityTypeTags.func_232896_a_(new ResourceLocation(MODID, "brazier_whitelist").toString());
public static final ITag<EntityType<?>> BRAZIER_BLACKLIST = EntityTypeTags.func_232896_a_(new ResourceLocation(MODID, "brazier_blacklist").toString());
public static final ITag<Item> TORCHES = ItemTags.makeWrapperTag(new ResourceLocation(MODID, "torches").toString());

public static final ITag<Item> ASH_TAG = ItemTags.makeWrapperTag(new ResourceLocation(MODID, "ash").toString());
public static final ITag<Item> WARPED_WART_TAG = ItemTags.makeWrapperTag(new ResourceLocation(MODID, "warped_wart").toString());

public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Brazier.MODID);
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Brazier.MODID);
public static final DeferredRegister<TileEntityType<?>> TILES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, Brazier.MODID);
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 DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
public static final DeferredRegister<TileEntityType<?>> TILES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, MODID);
public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, MODID);
public static final DeferredRegister<ParticleType<?>> PARTICLES = DeferredRegister.create(ForgeRegistries.PARTICLE_TYPES, MODID);

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

Expand All @@ -73,9 +79,13 @@ public class Content {
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_FLAME = ITEMS.register("living_flame", () -> new Item(new Item.Properties().group(ItemGroup.MATERIALS).rarity(Rarity.UNCOMMON)));
public static final RegistryObject<Item> LIVING_TORCH = ITEMS.register("living_torch", LivingTorch::new);

public static final RegistryObject<Item> ASH = ITEMS.register("ash", () -> new Item(new Item.Properties().group(ItemGroup.MATERIALS)));
public static final RegistryObject<Item> WARPED_NETHERWART = ITEMS.register("warped_nether_wart", () -> new Item(new Item.Properties().group(ItemGroup.MATERIALS)));
public static final RegistryObject<Block> SPAWN_POWDER = registerBlock("spawn_powder", SpawnPowder::new, p -> p.group(ItemGroup.MATERIALS));

public static final RegistryObject<EntityType<Crazed>> CRAZED = ENTITIES.register("crazed", () -> EntityType.Builder.<Crazed>create(Crazed::new, EntityClassification.MONSTER)
.setCustomClientFactory((s, w) -> new Crazed(w))
.immuneToFire().build("crazed"));
Expand Down Expand Up @@ -142,5 +152,7 @@ public static void clientSetup(Minecraft mc) {
.forEach(b -> RenderTypeLookup.setRenderLayer(b, RenderType.getCutout()));

BRAZIER_TILE.ifPresent(tile -> ClientRegistry.bindTileEntityRenderer(tile, BrazierRenderer::new));

SPAWN_POWDER.ifPresent(b -> RenderTypeLookup.setRenderLayer(b, RenderType.getCutout()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.possible_triangle.brazier.Content;
import com.possible_triangle.brazier.block.tile.BrazierTile;
import com.possible_triangle.brazier.config.BrazierConfig;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
Expand Down Expand Up @@ -81,6 +82,15 @@ public static boolean prevents(SpawnReason reason) {
@SubscribeEvent
public static void mobSpawn(LivingSpawnEvent.CheckSpawn event) {
BlockPos pos = new BlockPos(event.getX(), event.getY(), event.getZ());

// Check for spawn powder
if(BrazierConfig.SERVER.SPAWN_POWDER.get()) {
Block block = event.getWorld().getBlockState(pos).getBlock();
if(Content.SPAWN_POWDER.filter(block::equals).isPresent()) {
return;
}
}

if (prevents(event.getSpawnReason()) && prevents(event.getEntity()) && BrazierTile.inRange(pos))
event.setResult(Event.Result.DENY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

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.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
Expand All @@ -26,11 +26,13 @@ public LazyWallTorchBlock(Supplier<? extends IParticleData> particle) {
@OnlyIn(Dist.CLIENT)
@Override
public void animateTick(BlockState state, World world, BlockPos pos, Random rand) {
Direction direction = state.get(HORIZONTAL_FACING);
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);
Direction direction1 = direction.getOpposite();
world.addParticle(ParticleTypes.SMOKE, d0 + 0.27D * (double)direction1.getXOffset(), d1 + 0.22D, d2 + 0.27D * (double)direction1.getZOffset(), 0.0D, 0.0D, 0.0D);
world.addParticle(this.particle.get(), d0 + 0.27D * (double)direction1.getXOffset(), d1 + 0.22D, d2 + 0.27D * (double)direction1.getZOffset(), 0.0D, 0.0D, 0.0D);
}

}
42 changes: 42 additions & 0 deletions src/main/java/com/possible_triangle/brazier/block/SpawnPowder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.possible_triangle.brazier.block;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.material.Material;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.IWorldReader;

public class SpawnPowder extends Block {

private static final VoxelShape SHAPE = Block.makeCuboidShape(2.0D, 0.0D, 2.0D, 14.0D, 1.0D, 14.0D);

public SpawnPowder() {
super(Properties.create(Material.MISCELLANEOUS)
.doesNotBlockMovement()
.zeroHardnessAndResistance()
.func_235838_a_($ -> 1)
);
}

@Override
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) {
return SHAPE;
}

@Override
public boolean isValidPosition(BlockState state, IWorldReader world, BlockPos pos) {
BlockState below = world.getBlockState(pos.down());
return below.isSolidSide(world, pos.down(), Direction.UP);
}

public BlockState updatePostPlacement(BlockState state, Direction facing, BlockState neighbor, IWorld world, BlockPos block, BlockPos facingPos) {
return !state.isValidPosition(world, block) ? Blocks.AIR.getDefaultState() : super.updatePostPlacement(state, facing, neighbor, world, block, facingPos);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.world.server.ServerWorld;

import java.util.HashMap;
Expand All @@ -41,6 +40,7 @@ public static boolean isBorder(Vector3d pos) {
public static boolean inRange(BlockPos pos) {
synchronized (BRAZIERS) {
return BRAZIERS.entrySet().stream().anyMatch(e -> {
if(!BrazierConfig.SERVER.PROTECT_ABOVE.get() && e.getKey().getY() < pos.getY()) return false;
double dist = DistanceHandler.getDistance(pos, e.getKey());
int maxDist = e.getValue() * e.getValue();
return dist <= maxDist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class BrazierServerConfig {
public final ForgeConfigSpec.IntValue MAX_HEIGHT;
public final ForgeConfigSpec.IntValue RANGE_PER_LEVEL;
public final ForgeConfigSpec.IntValue BASE_RANGE;
public final ForgeConfigSpec.BooleanValue PROTECT_ABOVE;

public final ForgeConfigSpec.BooleanValue SPAWN_POWDER;

public final ForgeConfigSpec.EnumValue<DistanceHandler.Type> DISTANCE_CALC;

Expand Down Expand Up @@ -39,6 +42,16 @@ public BrazierServerConfig(ForgeConfigSpec.Builder builder) {
.translation("config.brazier.distanceCalc")
.defineEnum("distanceCalc", DistanceHandler.Type.CYLINDER);

PROTECT_ABOVE = builder
.comment("Should the brazier protect blocks above it too?")
.translation("config.brazier.protectAbove")
.define("protectAbove", false);

SPAWN_POWDER = builder
.comment("Enable to spawn powder block?")
.translation("config.brazier.spawnPowder")
.define("spawnPowder", true);

builder.pop().comment("Options related to the acquisition of the living flame").push("acquisition");

JUNGLE_LOOT = builder
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/possible_triangle/brazier/data/Blocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ public Blocks(DataGenerator generator, ExistingFileHelper fileHelper) {
super(generator, Brazier.MODID, fileHelper);
}

private ResourceLocation extend(ResourceLocation in, String with) {
return new ResourceLocation(in.getNamespace(), in.getPath() + with);
}

@Override
protected void registerStatesAndModels() {

Content.BRAZIER.ifPresent(b -> getVariantBuilder(b).forAllStates(s -> {
boolean lit = s.get(BrazierBlock.LIT);
ResourceLocation r = blockTexture(b);
ResourceLocation model = lit ? new ResourceLocation(r.getNamespace(), r.getPath() + "_lit") : r;
ResourceLocation model = lit ? extend(r, "_lit") : r;
return ConfiguredModel.builder()
.modelFile(this.models().getExistingFile(model))
.build();
Expand Down Expand Up @@ -57,5 +61,16 @@ protected void registerStatesAndModels() {
}
);

Content.SPAWN_POWDER.ifPresent(b -> simpleBlock(b,
models().getBuilder(b.getRegistryName().getPath())
.texture("particle", blockTexture(b))
.texture("texture", blockTexture(b))
.element().from(0, 0.25F, 0).to(16, 0.25F, 16)
.shade(false)
.face(Direction.UP).texture("#texture").uvs(0, 0, 16, 16).end()
.face(Direction.DOWN).texture("#texture").uvs(0, 16, 16, 0).end()
.end().ao(false)
));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected void registerModels() {
.map(ResourceLocation::getPath)
.ifPresent(b -> this.withExistingParent(b, modLoc("block/" + b)));

Stream.of(Content.LIVING_FLAME).forEach(c -> c
Stream.of(Content.LIVING_FLAME, Content.SPAWN_POWDER, Content.WARPED_NETHERWART, Content.ASH).forEach(c -> c
.map(ForgeRegistryEntry::getRegistryName)
.map(ResourceLocation::getPath)
.ifPresent(i -> singleTexture(i, mcLoc("item/generated"), "layer0", modLoc("item/" + i)))
Expand Down
30 changes: 29 additions & 1 deletion src/main/java/com/possible_triangle/brazier/data/Loot.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.possible_triangle.brazier.data;

import com.possible_triangle.brazier.Content;
import net.minecraft.advancements.criterion.StatePropertiesPredicate;
import net.minecraft.block.Blocks;
import net.minecraft.block.NetherWartBlock;
import net.minecraft.data.DataGenerator;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Items;
import net.minecraft.loot.*;
import net.minecraft.loot.conditions.BlockStateProperty;
import net.minecraft.loot.conditions.RandomChance;
import net.minecraft.loot.conditions.SurvivesExplosion;
import net.minecraft.loot.functions.LootingEnchantBonus;
import net.minecraft.loot.functions.SetCount;
import net.minecraftforge.event.LootTableLoadEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.Mod;

Expand All @@ -21,13 +30,32 @@ public Loot(DataGenerator generator) {

@SubscribeEvent
public static void onLootLoaded(LootTableLoadEvent event) {
boolean noNetherEx = !ModList.get().isLoaded("nether_extension");

if (event.getName().equals(LootTables.CHESTS_JUNGLE_TEMPLE)) {
Content.LIVING_FLAME.ifPresent(flame ->
event.getTable().addPool(LootPool.builder()
.addEntry(ItemLootEntry.builder(flame))
.addEntry(EmptyLootEntry.func_216167_a().weight(1))
.build())
);
} else if (event.getName().equals(EntityType.WITHER_SKELETON.getLootTable()) && !noNetherEx) {
Content.ASH.ifPresent(ash -> event.getTable().addPool(LootPool.builder()
.addEntry(ItemLootEntry.builder(ash)
.acceptFunction(SetCount.builder(RandomValueRange.of(-1, 1)))
.acceptFunction(LootingEnchantBonus.builder(RandomValueRange.of(0, 1)))
)
.build())
);
} else if (event.getName().equals(Blocks.NETHER_WART.getLootTable())) {
Content.WARPED_NETHERWART.ifPresent(wart -> event.getTable().addPool(LootPool.builder()
.addEntry(ItemLootEntry.builder(wart).acceptFunction(SetCount.builder(RandomValueRange.of(-1, 1))
.acceptCondition(RandomChance.builder(0.02F))
.acceptCondition(BlockStateProperty.builder(Blocks.NETHER_WART)
.fromProperties(StatePropertiesPredicate.Builder.newBuilder().withIntProp(NetherWartBlock.AGE, 3)))
))
.build())
);
}
}

Expand All @@ -39,7 +67,7 @@ protected void addTables() {
).setParameterSet(LootParameterSets.ENTITY)
));

Stream.of(Content.BRAZIER, Content.LIVING_TORCH_BLOCK, Content.LIVING_TORCH_BLOCK_WALL)
Stream.of(Content.BRAZIER, Content.LIVING_TORCH_BLOCK, Content.LIVING_TORCH_BLOCK_WALL, Content.SPAWN_POWDER)
.filter(RegistryObject::isPresent).map(RegistryObject::get)
.forEach(block -> lootTables.put(block.getLootTable(), LootTable.builder()
.addLootPool(LootPool.builder().rolls(ConstantRange.of(1))
Expand Down
Loading