Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Added snow under DHD and automatic snow camo in gate blocks
Browse files Browse the repository at this point in the history
Fixed #257
  • Loading branch information
MrJake222 committed Feb 8, 2021
1 parent bd29c92 commit 0350bd3
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 45 deletions.
6 changes: 6 additions & 0 deletions src/main/java/mrjake/aunis/AunisProps.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import mrjake.aunis.block.BeamerBlock;
import mrjake.aunis.block.CapacitorBlock;
import mrjake.aunis.block.DHDBlock;
import mrjake.aunis.block.InvisibleBlock;
import mrjake.aunis.block.stargate.StargateMilkyWayMemberBlock;
import mrjake.aunis.block.stargate.StargateOrlinMemberBlock;
Expand Down Expand Up @@ -76,4 +77,9 @@ public class AunisProps {
* Used by {@link BeamerBlock} to display textures.
*/
public static final PropertyBeamerMode BEAMER_MODE = PropertyBeamerMode.create("mode");

/**
* Used by {@link DHDBlock} to determine whether it's snow layer on the bottom should be rendered.
*/
public static final PropertyBool SNOWY = PropertyBool.create("snowy");
}
27 changes: 25 additions & 2 deletions src/main/java/mrjake/aunis/block/DHDBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.state.pattern.BlockMatcher;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
Expand Down Expand Up @@ -46,7 +48,8 @@ public DHDBlock() {
setCreativeTab(Aunis.aunisCreativeTab);

setDefaultState(blockState.getBaseState()
.withProperty(AunisProps.ROTATION_HORIZONTAL, 0));
.withProperty(AunisProps.ROTATION_HORIZONTAL, 0)
.withProperty(AunisProps.SNOWY, false));

setLightOpacity(0);

Expand All @@ -58,7 +61,7 @@ public DHDBlock() {
// ------------------------------------------------------------------------
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, AunisProps.ROTATION_HORIZONTAL);
return new BlockStateContainer(this, AunisProps.ROTATION_HORIZONTAL, AunisProps.SNOWY);
}

@Override
Expand All @@ -73,6 +76,26 @@ public IBlockState getStateFromMeta(int meta) {
.withProperty(AunisProps.ROTATION_HORIZONTAL, meta);
}

public final static BlockMatcher SNOW_MATCHER = BlockMatcher.forBlock(Blocks.SNOW_LAYER);

@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
return state.withProperty(AunisProps.SNOWY, isSnowAroundBlock(world, pos));
}

public static boolean isSnowAroundBlock(IBlockAccess world, BlockPos inPos) {

// Check if 4 adjacent blocks are snow layers
for (EnumFacing facing : EnumFacing.HORIZONTALS) {
BlockPos pos = inPos.offset(facing);
if (!SNOW_MATCHER.apply(world.getBlockState(pos))) {
return false;
}
}

return true;
}

// ------------------------------------------------------------------------
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import mrjake.aunis.stargate.merging.StargateAbstractMergeHelper;
import mrjake.aunis.tileentity.stargate.StargateAbstractBaseTile;
import mrjake.aunis.tileentity.stargate.StargateAbstractMemberTile;
import mrjake.aunis.tileentity.stargate.StargateClassicMemberTile;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
Expand Down Expand Up @@ -46,7 +47,7 @@ public StargateAbstractMemberBlock(String blockName) {
public void breakBlock(World world, BlockPos pos, IBlockState state) {
StargateAbstractMemberTile memberTile = (StargateAbstractMemberTile) world.getTileEntity(pos);
StargateAbstractBaseTile gateTile = memberTile.getBaseTile(world);

if (gateTile != null) {
gateTile.updateMergeState(false, world.getBlockState(gateTile.getPos()).getValue(AunisProps.FACING_HORIZONTAL));
}
Expand Down Expand Up @@ -104,7 +105,15 @@ public boolean isFullBlock(IBlockState state) {
}

@Override
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face) {
return BlockFaceShape.UNDEFINED;
public BlockFaceShape getBlockFaceShape(IBlockAccess world, IBlockState state, BlockPos pos, EnumFacing facing) {
if (state.getValue(AunisProps.RENDER_BLOCK)) {
// Rendering some block
StargateClassicMemberTile memberTile = (StargateClassicMemberTile) world.getTileEntity(pos);
if (memberTile != null && memberTile.getCamoState() != null) {
return memberTile.getCamoState().getBlockFaceShape(world, pos, facing);
}
}

return BlockFaceShape.UNDEFINED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import mrjake.aunis.Aunis;
import mrjake.aunis.AunisProps;
import mrjake.aunis.block.AunisBlocks;
import mrjake.aunis.block.DHDBlock;
import mrjake.aunis.gui.GuiIdEnum;
import mrjake.aunis.packet.AunisPacketHandler;
import mrjake.aunis.packet.StateUpdatePacketToClient;
import mrjake.aunis.stargate.CamoPropertiesHelper;
import mrjake.aunis.stargate.EnumMemberVariant;
import mrjake.aunis.state.StateTypeEnum;
import mrjake.aunis.tileentity.stargate.StargateAbstractBaseTile;
import mrjake.aunis.tileentity.stargate.StargateClassicMemberTile;
import net.minecraft.block.Block;
Expand Down Expand Up @@ -41,7 +39,6 @@
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;

public abstract class StargateClassicMemberBlock extends StargateAbstractMemberBlock {

Expand Down Expand Up @@ -127,10 +124,10 @@ public IBlockState getExtendedState(IBlockState state, IBlockAccess world, Block
StargateClassicMemberTile memberTile = (StargateClassicMemberTile) world.getTileEntity(pos);

if (memberTile != null) {
IBlockState doubleSlabState = memberTile.getCamoState();

if (doubleSlabState != null) {
return ((IExtendedBlockState) state).withProperty(AunisProps.CAMO_BLOCKSTATE, doubleSlabState);
IBlockState camoBlockState = memberTile.getCamoState();
if (camoBlockState != null) {
return ((IExtendedBlockState) state).withProperty(AunisProps.CAMO_BLOCKSTATE, camoBlockState);
}
}

Expand Down Expand Up @@ -161,6 +158,23 @@ public void registerCustomModel(IRegistry<ModelResourceLocation, IBakedModel> re
}
}

@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos) {
StargateClassicMemberTile memberTile = (StargateClassicMemberTile) world.getTileEntity(pos);

if (!world.isRemote && memberTile != null) {
// Server and tile entity exists

if (memberTile.isMerged() && memberTile.getCamoState() == null || DHDBlock.SNOW_MATCHER.apply(memberTile.getCamoState())) {
// Merged and camo is empty or it's snow
boolean snowAround = DHDBlock.isSnowAroundBlock(world, pos);

// Set camo to snow or null
memberTile.setCamoState(snowAround ? Blocks.SNOW_LAYER.getDefaultState() : null);
world.setBlockState(pos, state.withProperty(AunisProps.RENDER_BLOCK, snowAround));
}
}
}


// ------------------------------------------------------------------------
Expand Down Expand Up @@ -299,14 +313,11 @@ else if (blockSlab == Blocks.PURPUR_SLAB)
else {
world.setBlockState(pos, state.withProperty(AunisProps.RENDER_BLOCK, false), 0);
}

TargetPoint point = new TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 512);
AunisPacketHandler.INSTANCE.sendToAllTracking(new StateUpdatePacketToClient(pos, StateTypeEnum.CAMO_STATE, memberTile.getState(StateTypeEnum.CAMO_STATE)), point);

return true;
}

else {
else {
return heldItem != Item.getItemFromBlock(AunisBlocks.STARGATE_MILKY_WAY_MEMBER_BLOCK) &&
heldItem != Item.getItemFromBlock(AunisBlocks.STARGATE_MILKY_WAY_BASE_BLOCK) &&
heldItem != Item.getItemFromBlock(AunisBlocks.STARGATE_UNIVERSE_BASE_BLOCK) &&
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/mrjake/aunis/renderer/BlockRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand All @@ -19,12 +20,16 @@ public static void render(World world, BlockPos pos, IBlockState state) {
IBakedModel model = blockRendererDispatcher.getModelForState(state);

GlStateManager.disableLighting();

Minecraft.getMinecraft().entityRenderer.disableLightmap();
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);

Tessellator tessellator = Tessellator.getInstance();
tessellator.getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
blockRendererDispatcher.getBlockModelRenderer().renderModelFlat(world, model, state, pos, tessellator.getBuffer(), false, 0);
tessellator.draw();

GlStateManager.enableLighting();
Minecraft.getMinecraft().entityRenderer.enableLightmap();

}
}
11 changes: 10 additions & 1 deletion src/main/java/mrjake/aunis/renderer/DHDRenderer.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package mrjake.aunis.renderer;

import mrjake.aunis.AunisProps;
import mrjake.aunis.loader.ElementEnum;
import mrjake.aunis.loader.model.ModelLoader;
import mrjake.aunis.stargate.network.SymbolMilkyWayEnum;
import mrjake.aunis.tileentity.DHDTile;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;

public class DHDRenderer extends TileEntitySpecialRenderer<DHDTile> {

Expand All @@ -15,8 +18,13 @@ public void render(DHDTile te, double x, double y, double z, float partialTicks,

if (rendererState != null) {
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, z);

GlStateManager.translate(x+0.5, y, z+0.5);
if (te.getWorld().getBlockState(te.getPos()).getActualState(te.getWorld(), te.getPos()).getValue(AunisProps.SNOWY)) {
BlockRenderer.render(getWorld(), new BlockPos(0, 0, 0), Blocks.SNOW_LAYER.getDefaultState());
}

GlStateManager.translate(0.5, 0, 0.5);
GlStateManager.rotate(rendererState.horizontalRotation, 0, 1, 0);

ElementEnum.MILKYWAY_DHD.bindTextureAndRender(rendererState.getBiomeOverlay());
Expand All @@ -26,6 +34,7 @@ public void render(DHDTile te, double x, double y, double z, float partialTicks,
ModelLoader.getModel(symbol.modelResource).render();
}


GlStateManager.popMatrix();

rendererState.iterate(getWorld(), partialTicks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
import mrjake.aunis.util.AunisAxisAlignedBB;
import mrjake.aunis.util.FacingToRotation;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
Expand Down Expand Up @@ -68,15 +66,11 @@ public void render(StargateAbstractBaseTile te, double x, double y, double z, fl
renderKawoosh(rendererState, partialTicks);
}

else {
bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);

else {
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_CONSTANT_ALPHA, GL11.GL_ONE_MINUS_CONSTANT_ALPHA);
GL14.glBlendColor(0, 0, 0, 0.7f);

Minecraft.getMinecraft().entityRenderer.disableLightmap();


for (Map.Entry<BlockPos, IBlockState> entry : getMemberBlockStates(te.getMergeHelper(), rendererState.facing).entrySet()) {
BlockPos pos = entry.getKey().rotate(FacingToRotation.get(rendererState.facing));

Expand All @@ -85,7 +79,6 @@ public void render(StargateAbstractBaseTile te, double x, double y, double z, fl
BlockRenderer.render(getWorld(), pos, entry.getValue());
}

Minecraft.getMinecraft().entityRenderer.enableLightmap();
GlStateManager.disableBlend();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import mrjake.aunis.AunisProps;
import mrjake.aunis.block.stargate.StargateMilkyWayBaseBlock;
import mrjake.aunis.block.stargate.StargateMilkyWayMemberBlock;
import mrjake.aunis.packet.AunisPacketHandler;
import mrjake.aunis.packet.StateUpdatePacketToClient;
import mrjake.aunis.stargate.EnumMemberVariant;
import mrjake.aunis.state.StateTypeEnum;
import mrjake.aunis.tileentity.stargate.StargateClassicMemberTile;
import mrjake.aunis.tileentity.stargate.StargateMilkyWayMemberTile;
import mrjake.aunis.util.FacingToRotation;
Expand All @@ -17,7 +14,6 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;

public abstract class StargateClassicMergeHelper extends StargateAbstractMergeHelper {

Expand All @@ -41,12 +37,13 @@ protected void updateMemberMergeStatus(World world, BlockPos checkPos, BlockPos
ItemStack camoStack = memberTile.getCamoItemStack();
if (camoStack != null) {
InventoryHelper.spawnItemStack(world, checkPos.getX(), checkPos.getY(), checkPos.getZ(), camoStack);
}

if (memberTile.getCamoState() != null) {
memberTile.setCamoState(null);

TargetPoint point = new TargetPoint(world.provider.getDimension(), checkPos.getX(), checkPos.getY(), checkPos.getZ(), 512);
AunisPacketHandler.INSTANCE.sendToAllTracking(new StateUpdatePacketToClient(checkPos, StateTypeEnum.CAMO_STATE, memberTile.getState(StateTypeEnum.CAMO_STATE)), point);
}

// This also sets merge status
memberTile.setBasePos(shouldBeMerged ? basePos : null);

world.setBlockState(checkPos, state.withProperty(AunisProps.RENDER_BLOCK, !shouldBeMerged), 3);
Expand Down
Loading

0 comments on commit 0350bd3

Please sign in to comment.