Skip to content

Commit

Permalink
Make camo blocks for Destiny's CO2 Blasters
Browse files Browse the repository at this point in the history
  • Loading branch information
MineDragonCZ committed Jul 4, 2023
1 parent fb56da8 commit a225091
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.daemon=true
org.gradle.parallel=true
# Minecraft Version
mc_version=1.12.2
mod_version=4.11.1.0-pre4
mod_version=4.11.1.0-pre5
forge_version=14.23.5.2860
mappings_version=snapshot_20171003
# Dependencies
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/tauri/dev/jsg/block/props/DestinyVentBlock.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package tauri.dev.jsg.block.props;

import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
Expand All @@ -19,13 +23,15 @@
import net.minecraftforge.fml.relauncher.SideOnly;
import tauri.dev.jsg.JSG;
import tauri.dev.jsg.block.JSGBlock;
import tauri.dev.jsg.config.JSGConfigUtil;
import tauri.dev.jsg.creativetabs.JSGCreativeTabsHandler;
import tauri.dev.jsg.renderer.props.DestinyVentRenderer;
import tauri.dev.jsg.tileentity.props.DestinyVentTile;
import tauri.dev.jsg.util.main.JSGProps;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

@SuppressWarnings("deprecation")
public class DestinyVentBlock extends JSGBlock {
Expand Down Expand Up @@ -74,6 +80,30 @@ public void onBlockPlacedBy(World world, @Nonnull BlockPos pos, @Nonnull IBlockS
world.setBlockState(pos, state);
}

@Override
@ParametersAreNonnullByDefault
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack heldItemStack = player.getHeldItem(EnumHand.MAIN_HAND);

if (heldItemStack.isEmpty()) return false;
if (!(heldItemStack.getItem() instanceof ItemBlock)) return false;

if (!JSGConfigUtil.canBeUsedAsCamoBlock(Block.getBlockFromItem(heldItemStack.getItem()).getBlockState().getBaseState())) {
return false;
}
if (world.isRemote) return false;

DestinyVentTile ventTile = (DestinyVentTile) world.getTileEntity(pos);

if (ventTile == null) return false;

Block block = Block.getBlockFromItem(heldItemStack.getItem());
int meta = heldItemStack.getMetadata();
ventTile.setCamoState(block.getStateFromMeta(meta));

return true;
}

// --------------------------------------------------------------------------------------

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package tauri.dev.jsg.renderer.props;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import tauri.dev.jsg.loader.ElementEnum;
import tauri.dev.jsg.loader.texture.TextureLoader;
import tauri.dev.jsg.particle.ParticleBlenderCOBlast;
import tauri.dev.jsg.renderer.biomes.BiomeOverlayEnum;
import tauri.dev.jsg.tileentity.props.DestinyVentTile;
import tauri.dev.jsg.util.FacingHelper;
import tauri.dev.jsg.util.main.JSGProps;
Expand All @@ -20,6 +24,8 @@ public void render(@Nonnull DestinyVentTile te, double x, double y, double z, fl
float animationStage = te.getAnimationStage(tick);
boolean fireParticles = (animationStage == 1f);

IBlockState camoBlockState = te.getCamoState();

GlStateManager.pushMatrix();
GlStateManager.translate(x, y, z);
GlStateManager.translate(0.5, 0f, 0.5);
Expand All @@ -35,7 +41,16 @@ public void render(@Nonnull DestinyVentTile te, double x, double y, double z, fl
ElementEnum.DESTINY_VENT_HOLE.bindTextureAndRender();
GlStateManager.pushMatrix();
GlStateManager.rotate((70f * animationStage), 1, 0, 0);
ElementEnum.DESTINY_VENT_MOVING.bindTextureAndRender();

if(camoBlockState == null){
ElementEnum.DESTINY_VENT_MOVING.bindTexture(BiomeOverlayEnum.NORMAL);
}
else{
ResourceLocation overlayResource = TextureLoader.getBlockTexture(camoBlockState);
Minecraft.getMinecraft().getTextureManager().bindTexture(overlayResource);
}

ElementEnum.DESTINY_VENT_MOVING.render();
if (fireParticles) {
for (int i = 0; i < 50; i++) {
boolean orange = (i < 25);
Expand Down
138 changes: 127 additions & 11 deletions src/main/java/tauri/dev/jsg/tileentity/props/DestinyVentTile.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package tauri.dev.jsg.tileentity.props;

import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tauri.dev.jsg.JSG;
import tauri.dev.jsg.packet.JSGPacketHandler;
import tauri.dev.jsg.packet.StateUpdateRequestToServer;
import tauri.dev.jsg.sound.JSGSoundHelper;
import tauri.dev.jsg.sound.SoundEventEnum;
import tauri.dev.jsg.state.State;
import tauri.dev.jsg.state.StateTypeEnum;
import tauri.dev.jsg.state.stargate.StargateCamoState;

import javax.annotation.Nonnull;
import java.util.Objects;

public class DestinyVentTile extends DestinyBearingTile {

public float getAnimationStage(double tick){
public float getAnimationStage(double tick) {
double time = Math.max((tick - animationStart - ANIMATION_DELAY_BEFORE), 0);
float animationStage = 0;
if (time <= (ANIMATION_DELAY_BETWEEN + OPEN_ANIMATION_LENGTH * 2))
Expand Down Expand Up @@ -64,17 +74,27 @@ public DestinyVentRenderState getRendererState() {
return rendererState;
}

@Override
public void onLoad() {
super.onLoad();
if (!world.isRemote) {
sendState(StateTypeEnum.CAMO_STATE, getState(StateTypeEnum.CAMO_STATE));
} else {
JSGPacketHandler.INSTANCE.sendToServer(new StateUpdateRequestToServer(pos, StateTypeEnum.CAMO_STATE));
}
}

@Override
public void update() {
super.update();

if(!world.isRemote) {
if (!world.isRemote) {
boolean isOpen = (getAnimationStage(world.getTotalWorldTime()) == 1);

if (!isOpen && soundPlayed) {
soundPlayed = false;
markDirty();
} else if(isOpen && !soundPlayed){
} else if (isOpen && !soundPlayed) {
soundPlayed = true;
markDirty();
JSGSoundHelper.playSoundEvent(world, pos, SoundEventEnum.DESTINY_BLASTER);
Expand All @@ -93,39 +113,135 @@ public void startAnimation() {
// Server
@Override
public State getState(StateTypeEnum stateType) {
if (stateType == StateTypeEnum.RENDERER_STATE) {
return getRendererState().animate(isActive, animationStart);
switch (stateType) {
case CAMO_STATE:
return new StargateCamoState(camoBlockState);

case RENDERER_STATE:
return getRendererState().animate(isActive, animationStart);

default:
return null;
}
return null;
}

// Server
@Override
public State createState(StateTypeEnum stateType) {
if (stateType == StateTypeEnum.RENDERER_STATE) {
return getRendererState().animate(isActive, animationStart);
switch (stateType) {
case CAMO_STATE:
return new StargateCamoState();
case RENDERER_STATE:
return getRendererState().animate(isActive, animationStart);
default:
return null;
}
return null;
}

// Client
@Override
public void setState(StateTypeEnum stateType, State state) {
if (stateType == StateTypeEnum.RENDERER_STATE) {
this.animationStart = ((DestinyVentRenderState) state).animationStart;
switch (stateType) {
case CAMO_STATE:
StargateCamoState memberState = (StargateCamoState) state;
camoBlockState = memberState.getState();

world.markBlockRangeForRenderUpdate(pos, pos);
break;
case RENDERER_STATE:
this.animationStart = ((DestinyVentRenderState) state).animationStart;
break;
default:
break;
}
}


// ---------------------------------------------------------------------------------
private IBlockState camoBlockState;

/**
* Should only be called from server. Updates camoBlockState and
* syncs the change to clients.
*
* @param camoBlockState Camouflage block state.
*/
public void setCamoState(IBlockState camoBlockState) {
// JSG.logger.debug("Setting camo for " + pos + " to " + camoBlockState);

this.camoBlockState = camoBlockState;
markDirty();

if (!world.isRemote) {
sendState(StateTypeEnum.CAMO_STATE, getState(StateTypeEnum.CAMO_STATE));
} else {
JSG.warn("Tried to set camoBlockState from client. This won't work!");
}
}

public IBlockState getCamoState() {
return camoBlockState;
}

public ItemStack getCamoItemStack() {
if (camoBlockState != null) {
Block block = camoBlockState.getBlock();

if (block == Blocks.SNOW_LAYER)
return null;

int quantity = 1;
int meta;

if (block instanceof BlockSlab && ((BlockSlab) block).isDouble()) {
quantity = 2;
meta = block.getMetaFromState(camoBlockState);

if (block == Blocks.DOUBLE_STONE_SLAB)
block = Blocks.STONE_SLAB;

else if (block == Blocks.DOUBLE_STONE_SLAB2)
block = Blocks.STONE_SLAB2;

else if (block == Blocks.DOUBLE_WOODEN_SLAB)
block = Blocks.WOODEN_SLAB;

else if (block == Blocks.PURPUR_DOUBLE_SLAB)
block = Blocks.PURPUR_SLAB;
} else {
meta = block.getMetaFromState(camoBlockState);
}

return new ItemStack(block, quantity, meta);
} else {
return null;
}
}

// ------------------------------------------------------------

@Override
public void readFromNBT(@Nonnull NBTTagCompound compound) {
this.animationStart = compound.getLong("animationStart");

if (compound.hasKey("camoBlock")) {
Block dblSlabBlock = Block.getBlockFromName(compound.getString("camoBlock"));
if (dblSlabBlock != null)
camoBlockState = dblSlabBlock.getStateFromMeta(compound.getInteger("camoBlocMeta"));
}

super.readFromNBT(compound);
}

@Nonnull
@Override
public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound compound) {
compound.setLong("animationStart", animationStart);

if (camoBlockState != null) {
compound.setString("camoBlock", Objects.requireNonNull(camoBlockState.getBlock().getRegistryName()).toString());
compound.setInteger("camoBlocMeta", camoBlockState.getBlock().getMetaFromState(camoBlockState));
}
return super.writeToNBT(compound);
}
}

0 comments on commit a225091

Please sign in to comment.